Documentation ¶
Index ¶
- Constants
- Variables
- func ReadBigInt(reader *bufio.Reader) (value big.Int, e error)
- func ReadHexString(reader *bufio.Reader) string
- func RoundFixed8(val float64) (newVal float64)
- type Balance
- type NEOAddress
- type NativeAsset
- type NetworkFeeAmount
- type OpCode
- type Operation
- type ParameterType
- type Parser
- func (p *Parser) ContainsOperation(operation string) bool
- func (p *Parser) ContainsScriptHash(scripthash string) bool
- func (p *Parser) ContainsScriptHashAndOperation(scripthash string, operation string) bool
- func (p *Parser) FindScriptHashes() ([]string, error)
- func (p *Parser) GetListOfOperations() ([]string, error)
- func (p *Parser) GetListOfScriptHashes() ([]string, error)
- func (p *Parser) Parse(methodSignature interface{}) ([]interface{}, error)
- type ParserInterface
- type Properties
- type ScriptBuilder
- func (s *ScriptBuilder) Clear()
- func (s *ScriptBuilder) EmptyOutput() []byte
- func (s *ScriptBuilder) EmptyTransactionAttributes() []byte
- func (s ScriptBuilder) FullHexString() string
- func (s *ScriptBuilder) GenerateContractInvocationData(scriptHash ScriptHash, operation string, args []interface{}) []byte
- func (s *ScriptBuilder) GenerateContractInvocationScript(scriptHash ScriptHash, operation string, args []interface{}) []byte
- func (s *ScriptBuilder) GenerateTransactionAttributes(attributes map[TransactionAttribute][]byte) ([]byte, error)
- func (s *ScriptBuilder) GenerateTransactionInput(unspent Unspent, assetToSend NativeAsset, amountToSend float64, ...) ([]byte, error)
- func (s *ScriptBuilder) GenerateTransactionOutput(sender NEOAddress, receiver NEOAddress, unspent Unspent, ...) ([]byte, error)
- func (s *ScriptBuilder) GenerateTransactionOutputPayableGAS(sender NEOAddress, receiver NEOAddress, unspent Unspent, ...) ([]byte, error)
- func (s *ScriptBuilder) GenerateVerificationScripts(scripts []interface{}) []byte
- func (s *ScriptBuilder) GenerateVerificationScriptsMultiSig(signatures []TransactionSignature) []byte
- func (s *ScriptBuilder) Push(data interface{}) error
- func (s *ScriptBuilder) PushLength(count int)
- func (s *ScriptBuilder) PushOpCode(opcode OpCode)
- func (s *ScriptBuilder) PushSysCall(command string)
- func (s *ScriptBuilder) PushVarData(b []byte)
- func (s ScriptBuilder) ToBytes() []byte
- func (s *ScriptBuilder) ToScriptHash() []byte
- type ScriptBuilderInterface
- type ScriptHash
- type TokenAmount
- type TradingVersion
- type Transaction
- type TransactionAttribute
- type TransactionOutput
- type TransactionSignature
- type TransactionType
- type TransactionValidationScript
- type UTXO
- type Unspent
Constants ¶
View Source
const (
Uint160Length = 20
)
Variables ¶
View Source
var NativeAssets = map[string]NativeAsset{ "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": NEO, "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": GAS, }
Functions ¶
func ReadHexString ¶
func RoundFixed8 ¶
Types ¶
type Balance ¶
func (*Balance) SortMinFirst ¶
func (b *Balance) SortMinFirst()
func (*Balance) TotalAmount ¶
type NEOAddress ¶
type NEOAddress []byte
func NEOAddressFromScriptHash ¶
func NEOAddressFromScriptHash(scriptHashBytes []byte) NEOAddress
func ParseNEOAddress ¶
func ParseNEOAddress(address string) NEOAddress
func ReadNEOAddress ¶
func ReadNEOAddress(reader *bufio.Reader) (*NEOAddress, error)
func (NEOAddress) ToString ¶
func (n NEOAddress) ToString() string
type NativeAsset ¶
type NativeAsset string
const ( NEO NativeAsset = "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b" GAS NativeAsset = "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7" )
func (NativeAsset) ToLittleEndianBytes ¶
func (n NativeAsset) ToLittleEndianBytes() []byte
type NetworkFeeAmount ¶
type NetworkFeeAmount float64
type OpCode ¶
type OpCode byte
const ( // Constants PUSH0 OpCode = 0x00 // An empty array of bytes is pushed onto the stack. PUSHF OpCode = PUSH0 PUSHBYTES1 OpCode = 0x01 // 0x01-0x4B The next opcode bytes is data to be pushed onto the stack PUSHBYTES75 OpCode = 0x4B PUSHDATA1 OpCode = 0x4C // The next byte contains the number of bytes to be pushed onto the stack. PUSHDATA2 OpCode = 0x4D // The next two bytes contain the number of bytes to be pushed onto the stack. PUSHDATA4 OpCode = 0x4E // The next four bytes contain the number of bytes to be pushed onto the stack. PUSHM1 OpCode = 0x4F // The number -1 is pushed onto the stack. PUSH1 OpCode = 0x51 // The number 1 is pushed onto the stack. PUSHT OpCode = PUSH1 PUSH2 OpCode = 0x52 // The number 2 is pushed onto the stack. PUSH3 OpCode = 0x53 // The number 3 is pushed onto the stack. PUSH4 OpCode = 0x54 // The number 4 is pushed onto the stack. PUSH5 OpCode = 0x55 // The number 5 is pushed onto the stack. PUSH6 OpCode = 0x56 // The number 6 is pushed onto the stack. PUSH7 OpCode = 0x57 // The number 7 is pushed onto the stack. PUSH8 OpCode = 0x58 // The number 8 is pushed onto the stack. PUSH9 OpCode = 0x59 // The number 9 is pushed onto the stack. PUSH10 OpCode = 0x5A // The number 10 is pushed onto the stack. PUSH11 OpCode = 0x5B // The number 11 is pushed onto the stack. PUSH12 OpCode = 0x5C // The number 12 is pushed onto the stack. PUSH13 OpCode = 0x5D // The number 13 is pushed onto the stack. PUSH14 OpCode = 0x5E // The number 14 is pushed onto the stack. PUSH15 OpCode = 0x5F // The number 15 is pushed onto the stack. PUSH16 OpCode = 0x60 // The number 16 is pushed onto the stack. // Flow control NOP OpCode = 0x61 // Does nothing. JMP OpCode = 0x62 JMPIF OpCode = 0x63 JMPIFNOT OpCode = 0x64 CALL OpCode = 0x65 RET OpCode = 0x66 APPCALL OpCode = 0x67 SYSCALL OpCode = 0x68 TAILCALL OpCode = 0x69 // Stack DUPFROMALTSTACK OpCode = 0x6A TOALTSTACK OpCode = 0x6B // Puts the input onto the top of the alt stack. Removes it from the main stack. FROMALTSTACK OpCode = 0x6C // Puts the input onto the top of the main stack. Removes it from the alt stack. XDROP OpCode = 0x6D XSWAP OpCode = 0x72 XTUCK OpCode = 0x73 DEPTH OpCode = 0x74 // Puts the number of stack items onto the stack. DROP OpCode = 0x75 // Removes the top stack item. DUP OpCode = 0x76 // Duplicates the top stack item. NIP OpCode = 0x77 // Removes the second-to-top stack item. OVER OpCode = 0x78 // Copies the second-to-top stack item to the top. PICK OpCode = 0x79 // The item n back in the stack is copied to the top. ROLL OpCode = 0x7A // The item n back in the stack is moved to the top. ROT OpCode = 0x7B // The top three items on the stack are rotated to the left. SWAP OpCode = 0x7C // The top two items on the stack are swapped. TUCK OpCode = 0x7D // The item at the top of the stack is copied and inserted before the second-to-top item. // Splice CAT OpCode = 0x7E // Concatenates two strings. SUBSTR OpCode = 0x7F // Returns a section of a string. LEFT OpCode = 0x80 // Keeps only characters left of the specified point in a string. RIGHT OpCode = 0x81 // Keeps only characters right of the specified point in a string. SIZE OpCode = 0x82 // Returns the length of the input string. // Bitwise logic INVERT OpCode = 0x83 // Flips all of the bits in the input. AND OpCode = 0x84 // Boolean and between each bit in the inputs. OR OpCode = 0x85 // Boolean or between each bit in the inputs. XOR OpCode = 0x86 // Boolean exclusive or between each bit in the inputs. EQUAL OpCode = 0x87 // Returns 1 if the inputs are exactly equal 0 otherwise. // Arithmetic // Note: Arithmetic inputs are limited to signed 32-bit integers but may overflow their output. INC OpCode = 0x8B // 1 is added to the input. DEC OpCode = 0x8C // 1 is subtracted from the input. SIGN OpCode = 0x8D NEGATE OpCode = 0x8F // The sign of the input is flipped. ABS OpCode = 0x90 // The input is made positive. NOT OpCode = 0x91 // If the input is 0 or 1 it is flipped. Otherwise the output will be 0. NZ OpCode = 0x92 // Returns 0 if the input is 0. 1 otherwise. ADD OpCode = 0x93 // a is added to b. SUB OpCode = 0x94 // b is subtracted from a. MUL OpCode = 0x95 // a is multiplied by b. DIV OpCode = 0x96 // a is divided by b. MOD OpCode = 0x97 // Returns the remainder after dividing a by b. SHL OpCode = 0x98 // Shifts a left b bits preserving sign. SHR OpCode = 0x99 // Shifts a right b bits preserving sign. BOOLAND OpCode = 0x9A // If both a and b are not 0 the output is 1. Otherwise 0. BOOLOR OpCode = 0x9B // If a or b is not 0 the output is 1. Otherwise 0. NUMEQUAL OpCode = 0x9C // Returns 1 if the numbers are equal 0 otherwise. NUMNOTEQUAL OpCode = 0x9E // Returns 1 if the numbers are not equal 0 otherwise. LT OpCode = 0x9F // Returns 1 if a is less than b 0 otherwise. GT OpCode = 0xA0 // Returns 1 if a is greater than b 0 otherwise. LTE OpCode = 0xA1 // Returns 1 if a is less than or equal to b 0 otherwise. GTE OpCode = 0xA2 // Returns 1 if a is greater than or equal to b 0 otherwise. MIN OpCode = 0xA3 // Returns the smaller of a and b. MAX OpCode = 0xA4 // Returns the larger of a and b. WITHIN OpCode = 0xA5 // Returns 1 if x is within the specified range (left-inclusive) 0 otherwise. // Crypto //RIPEMD160 OpCode = 0xA6 // The input is hashed using RIPEMD-160. SHA1 OpCode = 0xA7 // The input is hashed using SHA-1. SHA256 OpCode = 0xA8 // The input is hashed using SHA-256. HASH160 OpCode = 0xA9 HASH256 OpCode = 0xAA CHECKSIG OpCode = 0xAC CHECKMULTISIG OpCode = 0xAE // Array ARRAYSIZE OpCode = 0xC0 PACK OpCode = 0xC1 UNPACK OpCode = 0xC2 PICKITEM OpCode = 0xC3 SETITEM OpCode = 0xC4 NEWARRAY OpCode = 0xC5 //用作引用類型 NEWSTRUCT OpCode = 0xC6 //用作值類型 APPEND OpCode = 0xC8 REVERSE OpCode = 0xC9 REMOVE OpCode = 0xCA // Exceptions THROW OpCode = 0xF0 THROWIFNOT OpCode = 0xF1 )
type ParameterType ¶
type ParameterType byte
const ( Signature ParameterType = 0x00 Boolean ParameterType = 0x01 Integer ParameterType = 0x02 Hash160 ParameterType = 0x03 Hash256 ParameterType = 0x04 ByteArray ParameterType = 0x05 PublicKey ParameterType = 0x06 String ParameterType = 0x07 Array ParameterType = 0x10 InteropInterface ParameterType = 0xf0 Void ParameterType = 0xff )
func (ParameterType) Byte ¶
func (p ParameterType) Byte() byte
type Parser ¶
type Parser struct {
Script string
}
func NewParserWithScript ¶
func (*Parser) ContainsOperation ¶
func (*Parser) ContainsScriptHash ¶
func (*Parser) ContainsScriptHashAndOperation ¶
func (*Parser) FindScriptHashes ¶
func (*Parser) GetListOfOperations ¶
func (*Parser) GetListOfScriptHashes ¶
type ParserInterface ¶
type ParserInterface interface { Parse(methodSignature interface{}) ([]interface{}, error) GetListOfOperations() ([]string, error) GetListOfScriptHashes() ([]string, error) ContainsOperation(operation string) bool ContainsScriptHash(scripthash string) bool ContainsScriptHashAndOperation(scripthash string, operation string) bool }
type Properties ¶
type Properties int
const ( NoProperty Properties = 0 HasStorage Properties = 1 << 0 HasDynamicInvoke Properties = 1 << 1 Payable Properties = 1 << 2 )
type ScriptBuilder ¶
type ScriptBuilder struct {
RawBytes []byte
}
func (*ScriptBuilder) Clear ¶
func (s *ScriptBuilder) Clear()
func (*ScriptBuilder) EmptyOutput ¶
func (s *ScriptBuilder) EmptyOutput() []byte
func (*ScriptBuilder) EmptyTransactionAttributes ¶
func (s *ScriptBuilder) EmptyTransactionAttributes() []byte
func (ScriptBuilder) FullHexString ¶
func (s ScriptBuilder) FullHexString() string
func (*ScriptBuilder) GenerateContractInvocationData ¶
func (s *ScriptBuilder) GenerateContractInvocationData(scriptHash ScriptHash, operation string, args []interface{}) []byte
This is in a format of main(string operation, []object args) in c#
func (*ScriptBuilder) GenerateContractInvocationScript ¶
func (s *ScriptBuilder) GenerateContractInvocationScript(scriptHash ScriptHash, operation string, args []interface{}) []byte
when generate the invokescript we don't need the length of the whole script
func (*ScriptBuilder) GenerateTransactionAttributes ¶
func (s *ScriptBuilder) GenerateTransactionAttributes(attributes map[TransactionAttribute][]byte) ([]byte, error)
func (*ScriptBuilder) GenerateTransactionInput ¶
func (s *ScriptBuilder) GenerateTransactionInput(unspent Unspent, assetToSend NativeAsset, amountToSend float64, networkFeeAmount NetworkFeeAmount) ([]byte, error)
func (*ScriptBuilder) GenerateTransactionOutput ¶
func (s *ScriptBuilder) GenerateTransactionOutput(sender NEOAddress, receiver NEOAddress, unspent Unspent, assetToSend NativeAsset, amountToSend float64, networkFeeAmount NetworkFeeAmount) ([]byte, error)
func (*ScriptBuilder) GenerateTransactionOutputPayableGAS ¶
func (s *ScriptBuilder) GenerateTransactionOutputPayableGAS(sender NEOAddress, receiver NEOAddress, unspent Unspent, assetToSend NativeAsset, amountToSend float64, networkFeeAmount NetworkFeeAmount, payableGAS float64) ([]byte, error)
func (*ScriptBuilder) GenerateVerificationScripts ¶
func (s *ScriptBuilder) GenerateVerificationScripts(scripts []interface{}) []byte
func (*ScriptBuilder) GenerateVerificationScriptsMultiSig ¶
func (s *ScriptBuilder) GenerateVerificationScriptsMultiSig(signatures []TransactionSignature) []byte
func (*ScriptBuilder) Push ¶
func (s *ScriptBuilder) Push(data interface{}) error
func (*ScriptBuilder) PushLength ¶
func (s *ScriptBuilder) PushLength(count int)
func (*ScriptBuilder) PushOpCode ¶
func (s *ScriptBuilder) PushOpCode(opcode OpCode)
func (*ScriptBuilder) PushSysCall ¶
func (s *ScriptBuilder) PushSysCall(command string)
func (*ScriptBuilder) PushVarData ¶
func (s *ScriptBuilder) PushVarData(b []byte)
func (ScriptBuilder) ToBytes ¶
func (s ScriptBuilder) ToBytes() []byte
func (*ScriptBuilder) ToScriptHash ¶
func (s *ScriptBuilder) ToScriptHash() []byte
type ScriptBuilderInterface ¶
type ScriptBuilderInterface interface { GenerateContractInvocationScript(scriptHash ScriptHash, operation string, args []interface{}) []byte GenerateContractInvocationData(scriptHash ScriptHash, operation string, args []interface{}) []byte GenerateTransactionAttributes(attributes map[TransactionAttribute][]byte) ([]byte, error) //this is to send the UTXO of asset that will be used in TransactionOutput GenerateTransactionInput(unspent Unspent, assetToSend NativeAsset, amountToSend float64, networkFeeAmount NetworkFeeAmount) ([]byte, error) GenerateTransactionOutput(sender NEOAddress, receiver NEOAddress, unspent Unspent, assetToSend NativeAsset, amountToSend float64, networkFeeAmount NetworkFeeAmount) ([]byte, error) GenerateTransactionOutputPayableGAS(sender NEOAddress, receiver NEOAddress, unspent Unspent, assetToSend NativeAsset, amountToSend float64, networkFeeAmount NetworkFeeAmount, payableGAS float64) ([]byte, error) EmptyOutput() []byte GenerateVerificationScripts(signatures []interface{}) []byte GenerateVerificationScriptsMultiSig(signatures []TransactionSignature) []byte EmptyTransactionAttributes() []byte ToBytes() []byte FullHexString() string Clear() //public method to wrap pushData Push(data interface{}) error PushVarData(data []byte) PushOpCode(opcode OpCode) PushSysCall(command string) ToScriptHash() []byte //UInt160 PushLength(count int) // contains filtered or unexported methods }
func NewScriptBuilder ¶
func NewScriptBuilder() ScriptBuilderInterface
type ScriptHash ¶
type ScriptHash []byte
func NewScriptHash ¶
func NewScriptHash(hexString string) (ScriptHash, error)
func (ScriptHash) ToBigEndian ¶
func (s ScriptHash) ToBigEndian() []byte
func (ScriptHash) ToString ¶
func (s ScriptHash) ToString() string
type TokenAmount ¶
type TokenAmount uint
type TradingVersion ¶
type TradingVersion byte //currently 0
const ( NEOTradingVersion TradingVersion = 0x00 NEOTradingVersionPayableGAS TradingVersion = 0x01 )
type Transaction ¶
type Transaction struct { Type TransactionType Version TradingVersion Data []byte Attributes []byte Inputs []byte Outputs []byte //scripts contains two parts, Invocation script and Verification script Script []byte GAS uint64 //only for version 1 }
func NewContractTransaction ¶
func NewContractTransaction() Transaction
func NewInvocationTransaction ¶
func NewInvocationTransaction() Transaction
func NewInvocationTransactionPayable ¶
func NewInvocationTransactionPayable() Transaction
func NewTransactionWithType ¶
func NewTransactionWithType(txType byte, version int) Transaction
func (*Transaction) ToBytes ¶
func (t *Transaction) ToBytes() []byte
func (*Transaction) ToHash256 ¶
func (t *Transaction) ToHash256() []byte
this ToHash256 returns little endian bytes. TXID is big endian bytes, so when calling json-rpc api we need to reverse it
func (*Transaction) ToTXID ¶
func (t *Transaction) ToTXID() string
type TransactionAttribute ¶
type TransactionAttribute byte
const ( ContractHash TransactionAttribute = 0x00 ECDH02 TransactionAttribute = 0x02 ECDH03 TransactionAttribute = 0x03 Script TransactionAttribute = 0x20 Vote TransactionAttribute = 0x30 DescriptionUrl TransactionAttribute = 0x81 Description TransactionAttribute = 0x90 Hash1 TransactionAttribute = 0xa1 Hash2 TransactionAttribute = 0xa2 Hash3 TransactionAttribute = 0xa3 Hash4 TransactionAttribute = 0xa4 Hash5 TransactionAttribute = 0xa5 Hash6 TransactionAttribute = 0xa6 Hash7 TransactionAttribute = 0xa7 Hash8 TransactionAttribute = 0xa8 Hash9 TransactionAttribute = 0xa9 Hash10 TransactionAttribute = 0xaa Hash11 TransactionAttribute = 0xab Hash12 TransactionAttribute = 0xac Hash13 TransactionAttribute = 0xad Hash14 TransactionAttribute = 0xae Hash15 TransactionAttribute = 0xaf Remark TransactionAttribute = 0xf0 Remark1 TransactionAttribute = 0xf1 Remark2 TransactionAttribute = 0xf2 Remark3 TransactionAttribute = 0xf3 Remark4 TransactionAttribute = 0xf4 Remark5 TransactionAttribute = 0xf5 Remark6 TransactionAttribute = 0xf6 Remark7 TransactionAttribute = 0xf7 Remark8 TransactionAttribute = 0xf8 Remark9 TransactionAttribute = 0xf9 Remark10 TransactionAttribute = 0xfa Remark11 TransactionAttribute = 0xfb Remark12 TransactionAttribute = 0xfc Remark13 TransactionAttribute = 0xfd Remark14 TransactionAttribute = 0xfe Remark15 TransactionAttribute = 0xf )
func (TransactionAttribute) ToByte ¶
func (t TransactionAttribute) ToByte() byte
type TransactionOutput ¶
type TransactionOutput struct { Asset NativeAsset Value int64 Address NEOAddress }
type TransactionSignature ¶
type TransactionType ¶
type TransactionType byte
const ( MinerTransaction TransactionType = 0x00 IssueTransaction TransactionType = 0x01 ClaimTransaction TransactionType = 0x02 EnrollmentTransaction TransactionType = 0x20 RegisterTransaction TransactionType = 0x40 ContractTransaction TransactionType = 0x80 StateTransaction TransactionType = 0x90 PublishTransaction TransactionType = 0xd0 InvocationTransaction TransactionType = 0xd1 )
type TransactionValidationScript ¶
naming base on NEO network protocol http://docs.neo.org/en-us/network/network-protocol.html
type Unspent ¶
type Unspent struct {
Assets map[NativeAsset]*Balance
}
Click to show internal directories.
Click to hide internal directories.