vmutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: AGPL-3.0 Imports: 5 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")
)

pre-define errors

View Source
var ErrUnresolvedJump = errors.New("unresolved jump target")

Functions

func CallContractProgram

func CallContractProgram(hash []byte) ([]byte, error)

CallContractProgram generates the script for control contract output follow BCRP(bytom contract register protocol)

func DefaultCoinbaseProgram

func DefaultCoinbaseProgram() ([]byte, error)

DefaultCoinbaseProgram generates the script for contorl coinbase output

func GetIssuanceProgramRestrictHeight

func GetIssuanceProgramRestrictHeight(program []byte) uint64

GetIssuanceProgramRestrictHeight return issuance program restrict height if height invalid return 0

func IsUnspendable

func IsUnspendable(prog []byte) bool

IsUnspendable checks if a contorl program is absolute failed

func P2PKHSigProgram

func P2PKHSigProgram(pubkeyHash []byte) ([]byte, error)

P2PKHSigProgram generates the script for control with pubkey hash

func P2SHProgram

func P2SHProgram(scriptHash []byte) ([]byte, error)

P2SHProgram generates the script for control with script hash

func P2SPMultiSigProgram

func P2SPMultiSigProgram(pubkeys []sm2.PubKey, nrequired int) ([]byte, error)

P2SPMultiSigProgram generates the script for control transaction output

func P2SPMultiSigProgramWithHeight

func P2SPMultiSigProgramWithHeight(pubkeys []sm2.PubKey, nrequired int, blockHeight uint64) ([]byte, error)

P2SPMultiSigProgramWithHeight generates the script with block height for control transaction output

func P2WPKHProgram

func P2WPKHProgram(hash []byte) ([]byte, error)

P2WPKHProgram return the segwit pay to public key hash

func P2WSHProgram

func P2WSHProgram(hash []byte) ([]byte, error)

P2WSHProgram return the segwit pay to script hash

func RegisterProgram

func RegisterProgram(contract []byte) ([]byte, error)

RegisterProgram generates the script for register contract output follow BCRP(bytom contract register protocol)

func RetireProgram

func RetireProgram(comment []byte) ([]byte, error)

RetireProgram generates the script for retire output

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) 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) AddUint64

func (b *Builder) AddUint64(n uint64) *Builder

AddInt64 adds a pushdata instruction for an integer value.

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