Documentation ¶
Index ¶
- Constants
- Variables
- func CalcTxHashForSig(scriptPubKey []byte, originalTx *types.Transaction, txInIdx int) (*crypto.HashType, error)
- func Validate(scriptSig, scriptPubKey *Script, tx *types.Transaction, txInIdx int) error
- type IssueParams
- type OpCode
- type Operand
- type Script
- func CreateSplitAddrScriptPrefix(addr types.Address) *Script
- func IssueTokenScript(pubKeyHash []byte, params *IssueParams) *Script
- func NewScript() *Script
- func NewScriptFromBytes(scriptBytes []byte) *Script
- func PayToPubKeyHashCLTVScript(pubKeyHash []byte, blockTimeOrHeight int64) *Script
- func PayToPubKeyHashScript(pubKeyHash []byte) *Script
- func SignatureScript(sig *crypto.Signature, pubKey []byte) *Script
- func SplitAddrScript(addrs []types.Address, weights []uint64) *Script
- func StandardCoinbaseSignatureScript(height uint32) *Script
- func TransferTokenScript(pubKeyHash []byte, params *TransferParams) *Script
- func (s *Script) AddOpCode(opCode OpCode) *Script
- func (s *Script) AddOperand(operand []byte) *Script
- func (s *Script) AddScript(script *Script) *Script
- func (s *Script) Disasm() string
- func (s *Script) ExtractAddress() (types.Address, error)
- func (s *Script) ExtractP2PKHAddress() ([]byte, error)
- func (s *Script) GetIssueParams() (*IssueParams, error)
- func (s *Script) GetSigOpCount() int
- func (s *Script) GetSplitAddrScriptPrefix() *Script
- func (s *Script) GetTransferParams() (*TransferParams, error)
- func (s *Script) IsPayToPubKeyHash() bool
- func (s *Script) IsPayToPubKeyHashCLTVScript() bool
- func (s *Script) IsPayToScriptHash() bool
- func (s *Script) IsRegisterCandidateScript(blockTimeOrHeight int64) bool
- func (s *Script) IsSplitAddrScript() bool
- func (s *Script) IsTokenIssue() bool
- func (s *Script) IsTokenTransfer() bool
- func (s *Script) P2PKHScriptPrefix() *Script
- func (s *Script) ParseSplitAddrScript() ([]types.Address, []uint64, error)
- type Stack
- type TokenID
- type TransferParams
Constants ¶
const (
LockTimeThreshold = 5e8 // Tue Nov 5 00:53:20 1985 UTC
)
constants
Variables ¶
var ( // script.go ErrScriptBound = errors.New("Program counter out of script bound") ErrNoEnoughDataOPPUSHDATA1 = errors.New("OP_PUSHDATA1 has not enough data") ErrNoEnoughDataOPPUSHDATA2 = errors.New("OP_PUSHDATA2 has not enough data") ErrNoEnoughDataOPPUSHDATA4 = errors.New("OP_PUSHDATA4 has not enough data") ErrInvalidStackOperation = errors.New("Invalid stack operation") ErrBadOpcode = errors.New("Bad opcode") ErrScriptEqualVerify = errors.New("Equality verification failure") ErrScriptSignatureVerifyFail = errors.New("Signature verification failure") ErrInputIndexOutOfBound = errors.New("input index out of bound") ErrAddressNotApplicable = errors.New("Address only applies to p2pkh and token txs") ErrOpReturn = errors.New("Encounter OP_RETURN") ErrInvalidSplitAddrScript = errors.New("Invalid split address script") ErrScriptLockTimeVerifyFail = errors.New("Check lock time verification failure") // stack.go ErrFinalStackEmpty = errors.New("Final stack empty") ErrFinalTopStackEleFalse = errors.New("Final top stack element false") ErrCountNegative = errors.New("Count is negative") )
error
var ( // TokenNameKey is the key for writing token name onchain TokenNameKey = []byte("Name") // TokenSymbolKey is the key for writing token symbol onchain TokenSymbolKey = []byte("Symbol") // TokenAmountKey is the key for writing token amount onchain TokenAmountKey = []byte("Amount") // TokenDecimalsKey is the key for writing token decimals onchain TokenDecimalsKey = []byte("Decimals") // TokenTxHashKey is the key for writing tx hash of token id onchain TokenTxHashKey = []byte("TokenTxHash") // TokenTxOutIdxKey is the key for writing tx output index of token id onchain TokenTxOutIdxKey = []byte("TokenTxOutIdx") )
Functions ¶
func CalcTxHashForSig ¶
func CalcTxHashForSig(scriptPubKey []byte, originalTx *types.Transaction, txInIdx int) (*crypto.HashType, error)
CalcTxHashForSig calculates the hash of a tx input, used for signature
Types ¶
type IssueParams ¶
IssueParams defines parameters for issuing ERC20-like tokens
type OpCode ¶
type OpCode byte
OpCode enum
const ( // push value OP0 OpCode = 0x00 // 0 OPFALSE OpCode = 0x00 // 0 - AKA OP0 OPDATA20 OpCode = 0x14 // 20 OPPUSHDATA1 OpCode = 0x4c // 76 OPPUSHDATA2 OpCode = 0x4d // 77 OPPUSHDATA4 OpCode = 0x4e // 78 OP1NEGATE OpCode = 0x4f // 79 OPRESERVED OpCode = 0x50 // 80 OP1 OpCode = 0x51 // 81 OPTRUE OpCode = 0x51 // 81 - AKA OP1 OP2 OpCode = 0x52 // 82 OP3 OpCode = 0x53 // 83 OP4 OpCode = 0x54 // 84 OP5 OpCode = 0x55 // 85 OP6 OpCode = 0x56 // 86 OP7 OpCode = 0x57 // 87 OP8 OpCode = 0x58 // 88 OP9 OpCode = 0x59 // 89 OP10 OpCode = 0x5a // 90 OP11 OpCode = 0x5b // 91 OP12 OpCode = 0x5c // 92 OP13 OpCode = 0x5d // 93 OP14 OpCode = 0x5e // 94 OP15 OpCode = 0x5f // 95 OP16 OpCode = 0x60 // 96 // control OPNOP OpCode = 0x61 // 97 OPVER OpCode = 0x62 // 98 OPIF OpCode = 0x63 // 99 OPNOTIF OpCode = 0x64 // 100 OPVERIF OpCode = 0x65 // 101 OPVERNOTIF OpCode = 0x66 // 102 OPELSE OpCode = 0x67 // 103 OPENDIF OpCode = 0x68 // 104 OPVERIFY OpCode = 0x69 // 105 OPRETURN OpCode = 0x6a // 106 // stack ops OPTOALTSTACK OpCode = 0x6b // 107 OPFROMALTSTACK OpCode = 0x6c // 108 OP2DROP OpCode = 0x6d // 109 OP2DUP OpCode = 0x6e // 110 OP3DUP OpCode = 0x6f // 111 OP2OVER OpCode = 0x70 // 112 OP2ROT OpCode = 0x71 // 113 OP2SWAP OpCode = 0x72 // 114 OPIFDUP OpCode = 0x73 // 115 OPDEPTH OpCode = 0x74 // 116 OPDROP OpCode = 0x75 // 117 OPDUP OpCode = 0x76 // 118 OPNIP OpCode = 0x77 // 119 OPOVER OpCode = 0x78 // 120 OPPICK OpCode = 0x79 // 121 OPROLL OpCode = 0x7a // 122 OPROT OpCode = 0x7b // 123 OPSWAP OpCode = 0x7c // 124 OPTUCK OpCode = 0x7d // 125 // splice ops OPCAT OpCode = 0x7e // 126 OPSUBSTR OpCode = 0x7f // 127 OPLEFT OpCode = 0x80 // 128 OPRIGHT OpCode = 0x81 // 129 OPSIZE OpCode = 0x82 // 130 // bit logic OPINVERT OpCode = 0x83 // 131 OPAND OpCode = 0x84 // 132 OPOR OpCode = 0x85 // 133 OPXOR OpCode = 0x86 // 134 OPEQUAL OpCode = 0x87 // 135 OPEQUALVERIFY OpCode = 0x88 // 136 OPRESERVED1 OpCode = 0x89 // 137 OPRESERVED2 OpCode = 0x8a // 138 // numeric OP1ADD OpCode = 0x8b // 139 OP1SUB OpCode = 0x8c // 140 OP2MUL OpCode = 0x8d // 141 OP2DIV OpCode = 0x8e // 142 OPNEGATE OpCode = 0x8f // 143 OPABS OpCode = 0x90 // 144 OPNOT OpCode = 0x91 // 145 OP0NOTEQUAL OpCode = 0x92 // 146 OPADD OpCode = 0x93 // 147 OPSUB OpCode = 0x94 // 148 OPMUL OpCode = 0x95 // 149 OPDIV OpCode = 0x96 // 150 OPMOD OpCode = 0x97 // 151 OPLSHIFT OpCode = 0x98 // 152 OPRSHIFT OpCode = 0x99 // 153 OPBOOLAND OpCode = 0x9a // 154 OPBOOLOR OpCode = 0x9b // 155 OPNUMEQUAL OpCode = 0x9c // 156 OPNUMEQUALVERIFY OpCode = 0x9d // 157 OPNUMNOTEQUAL OpCode = 0x9e // 158 OPLESSTHAN OpCode = 0x9f // 159 OPGREATERTHAN OpCode = 0xa0 // 160 OPLESSTHANOREQUAL OpCode = 0xa1 // 161 OPGREATERTHANOREQUAL OpCode = 0xa2 // 162 OPMIN OpCode = 0xa3 // 163 OPMAX OpCode = 0xa4 // 164 OPWITHIN OpCode = 0xa5 // 165 // crypto OPRIPEMD160 OpCode = 0xa6 // 166 OPSHA1 OpCode = 0xa7 // 167 OPSHA256 OpCode = 0xa8 // 168 OPHASH160 OpCode = 0xa9 // 169 OPHASH256 OpCode = 0xaa // 170 OPCODESEPARATOR OpCode = 0xab // 171 OPCHECKSIG OpCode = 0xac // 172 OPCHECKSIGVERIFY OpCode = 0xad // 173 OPCHECKMULTISIG OpCode = 0xae // 174 OPCHECKMULTISIGVERIFY OpCode = 0xaf // 175 OPCHECKLOCKTIMEVERIFY OpCode = 0xb0 // 176 )
These constants are based on bitcoin official opcodes
type Script ¶
type Script []byte
Script represents scripts
func CreateSplitAddrScriptPrefix ¶ added in v0.3.0
CreateSplitAddrScriptPrefix creates a script prefix for split address with a hashed address
func IssueTokenScript ¶
func IssueTokenScript(pubKeyHash []byte, params *IssueParams) *Script
IssueTokenScript creates a script to issue tokens to the specified address.
func NewScriptFromBytes ¶
NewScriptFromBytes returns a script from byte slice
func PayToPubKeyHashCLTVScript ¶ added in v0.3.0
PayToPubKeyHashCLTVScript creates a script to lock a transaction output to the specified address till a specific time or block height.
func PayToPubKeyHashScript ¶
PayToPubKeyHashScript creates a script to lock a transaction output to the specified address.
func SignatureScript ¶
SignatureScript creates a script to unlock a utxo.
func SplitAddrScript ¶ added in v0.3.0
SplitAddrScript returns a script to store a split address output
func StandardCoinbaseSignatureScript ¶
StandardCoinbaseSignatureScript returns a standard signature script for coinbase transaction.
func TransferTokenScript ¶
func TransferTokenScript(pubKeyHash []byte, params *TransferParams) *Script
TransferTokenScript creates a script to transfer tokens to the specified address.
func (*Script) AddOperand ¶
AddOperand adds an operand to the script
func (*Script) Disasm ¶
Disasm disassembles script in human readable format. If the script fails to parse, the returned string will contain the disassembled script up to the failure point, appended by the string '[Error: error info]'
func (*Script) ExtractAddress ¶
ExtractAddress returns address within the script
func (*Script) ExtractP2PKHAddress ¶ added in v0.3.0
ExtractP2PKHAddress returns address within the script
func (*Script) GetIssueParams ¶
func (s *Script) GetIssueParams() (*IssueParams, error)
GetIssueParams returns token issue parameters embedded in the script
func (*Script) GetSigOpCount ¶
GetSigOpCount returns number of signature operations in a script
func (*Script) GetSplitAddrScriptPrefix ¶ added in v0.3.0
GetSplitAddrScriptPrefix returns prefix of split addr script without and list of addresses and weights only called on split address script, so no need to check error
func (*Script) GetTransferParams ¶
func (s *Script) GetTransferParams() (*TransferParams, error)
GetTransferParams returns token transfer parameters embedded in the script
func (*Script) IsPayToPubKeyHash ¶
IsPayToPubKeyHash returns if the script is p2pkh
func (*Script) IsPayToPubKeyHashCLTVScript ¶ added in v0.3.0
IsPayToPubKeyHashCLTVScript returns if the script is p2pkhCLTV
func (*Script) IsPayToScriptHash ¶
IsPayToScriptHash returns if the script is p2sh
func (*Script) IsRegisterCandidateScript ¶ added in v0.3.0
IsRegisterCandidateScript returns if the script is register candidate script
func (*Script) IsSplitAddrScript ¶ added in v0.3.0
IsSplitAddrScript returns if the script is split address Note: assume OP_RETURN is only used for split address here. Add a magic number if OP_RETURN is used for something else
func (*Script) IsTokenIssue ¶
IsTokenIssue returns if the script is token issurance
func (*Script) IsTokenTransfer ¶
IsTokenTransfer returns if the script is token issurance
func (*Script) P2PKHScriptPrefix ¶
P2PKHScriptPrefix returns p2pkh prefix of token script
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is used when interpretting script
type TokenID ¶
type TokenID struct { // An outpoint uniquely identifies a token by its issurance tx and output index, // which contains all parameters of the token types.OutPoint }
TokenID uniquely identifies a token, consisting of tx hash and output index
func NewTokenID ¶
NewTokenID returns a new token ID
type TransferParams ¶
TransferParams defines parameters for transferring tokens