vmutil

package
v0.0.0-...-8b8382b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2019 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadValue       = errors.New("bad value")
	ErrMultisigFormat = errors.New("bad multisig program format")
)
View Source
var ErrUnresolvedJump = errors.New("unresolved jump target")

Functions

func BlockMultiSigProgram

func BlockMultiSigProgram(pubkeys []ed25519.PublicKey, nrequired int) ([]byte, error)

BlockMultiSigProgram returns a valid multisignature consensus program where nrequired of the keys in pubkeys are required to have signed the block for success. An ErrBadValue will be returned if nrequired is larger than the number of keys provided. The result is: BLOCKHASH <pubkey>... <nrequired> <npubkeys> CHECKMULTISIG

func IsUnspendable

func IsUnspendable(prog []byte) bool

func P2SPMultiSigProgram

func P2SPMultiSigProgram(pubkeys []ed25519.PublicKey, nrequired int) ([]byte, error)

func ParseBlockMultiSigProgram

func ParseBlockMultiSigProgram(script []byte) ([]ed25519.PublicKey, int, error)

func ParseP2SPMultiSigProgram

func ParseP2SPMultiSigProgram(program []byte) ([]ed25519.PublicKey, int, error)

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) AddData

func (b *Builder) AddData(data []byte) *Builder

AddData adds a pushdata instruction for a given byte string.

func (*Builder) AddInt64

func (b *Builder) AddInt64(n int64) *Builder

AddInt64 adds a pushdata instruction for an integer value.

func (*Builder) AddJump

func (b *Builder) AddJump(target int) *Builder

AddJump adds a JUMP opcode whose target is the given target number. The actual program location of the target does not need to be known yet, as long as SetJumpTarget is called before Build.

func (*Builder) AddJumpIf

func (b *Builder) AddJumpIf(target int) *Builder

AddJump adds a JUMPIF opcode whose target is the given target number. The actual program location of the target does not need to be known yet, as long as SetJumpTarget is called before Build.

func (*Builder) AddOp

func (b *Builder) AddOp(op vm.Op) *Builder

AddOp adds the given opcode to the program.

func (*Builder) AddRawBytes

func (b *Builder) AddRawBytes(data []byte) *Builder

AddRawBytes simply appends the given bytes to the program. (It does not introduce a pushdata opcode.)

func (*Builder) Build

func (b *Builder) Build() ([]byte, error)

Build produces the bytecode of the program. It first resolves any jumps in the program by filling in the addresses of their targets. This requires SetJumpTarget to be called prior to Build for each jump target used (in a call to AddJump or AddJumpIf). If any target's address hasn't been set in this way, this function produces ErrUnresolvedJump. There are no other error conditions.

func (*Builder) NewJumpTarget

func (b *Builder) NewJumpTarget() int

NewJumpTarget allocates a number that can be used as a jump target in AddJump and AddJumpIf. Call SetJumpTarget to associate the number with a program location.

func (*Builder) SetJumpTarget

func (b *Builder) SetJumpTarget(target int) *Builder

SetJumpTarget associates the given jump-target number with the current position in the program - namely, the program's length, such that the first instruction executed by a jump using this target will be whatever instruction is added next. It is legal for SetJumpTarget to be called at the end of the program, causing jumps using that target to fall off the end. There must be a call to SetJumpTarget for every jump target used before any call to Build.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL