ontologyTransaction

package
v1.2.27 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: GPL-3.0 Imports: 7 Imported by: 2

README

Ontology Transaction Driver

        transaction_test.go测试案例说明
        Test_case1    : ONT转账
        Test_case2    : ONG转账
        Test_case3    : 已解绑ONG提取

当前支持

        交易单构建
        交易单签名
        交易单合并
        交易单验签

TODO

        多签

Documentation

Index

Constants

View Source
const (
	AssetONT         = 0
	AssetONG         = 1
	AssetONGWithdraw = 2
)
View Source
const (
	DefaultGasPrice = uint64(500)
	DefaultGasLimit = uint64(20000)
)
View Source
const (
	ONTContractVersion = byte(0x00)
	ONGContractVersion = byte(0x00)
	ONTContractAddress = "0100000000000000000000000000000000000000"
	ONGContractAddress = "0200000000000000000000000000000000000000"
	TxTypeInvoke       = byte(0xD1)
	DefaultAttribute   = byte(0)
)
View Source
const (
	PushBytes75 = 0x4B
	PushData1   = 0x4C
	PushData2   = 0x4D
	PushData4   = 0x4E
)
View Source
const (
	MethodTransfer     = "transfer"
	MethodTransferV2   = "transferV2"
	MethodTransferFrom = "transferFrom"
	NativeInvokeName   = "Ontology.Native.Invoke"
)
View Source
const (
	OpCodePushM1          = byte(0x4F)
	OpCodeNewStruct       = byte(0xC6)
	OpCodeToALTStack      = byte(0x6B)
	OpCodeDupFromALTStack = byte(0x6A)
	OpCodeAppend          = byte(0xC8)
	OpCodePush0           = byte(0x00)
	OpCodePush1           = byte(0x51)
	OpCodeFromALTStack    = byte(0x6C)
	OpCodePack            = byte(0xC1)
	OpCodeSysCall         = byte(0x68)
	OpCodeCheckSig        = byte(0xAC)
	OpCodeCheckMultiSig   = byte(0xAE)
)
View Source
const AddressPrefix = byte(0x17)

Variables

View Source
var (
	CurveOrder     = []byte{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}
	HalfCurveOrder = []byte{0x7F, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDE, 0x73, 0x7D, 0x56, 0xD3, 0x8B, 0xCF, 0x42, 0x79, 0xDC, 0xE5, 0x61, 0x7E, 0x31, 0x92, 0xA8}
)
View Source
var (
	BitcoinAlphabet = NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
)

Alphabet: copy from https://en.wikipedia.org/wiki/Base58

View Source
var (
	ErrorInvalidBase58String = errors.New("invalid base58 string")
)

Errors

Functions

func Decode

func Decode(input string, alphabet *Alphabet) ([]byte, error)

Decode docode with custom alphabet

func DecodeCheck

func DecodeCheck(address string) (byte, []byte, error)

return prefix + hash + error

func Encode

func Encode(input []byte, alphabet *Alphabet) string

Encode encode with custom alphabet

func EncodeCheck

func EncodeCheck(prefix byte, hash []byte) string

func VerifyAndCombineRawTransaction added in v1.0.15

func VerifyAndCombineRawTransaction(emptyTrans string, sigpub []SigPub) (bool, string, error)

Types

type Alphabet

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

Alphabet The base58 alphabet object.

func NewAlphabet

func NewAlphabet(alphabet string) *Alphabet

NewAlphabet create a custom alphabet from 58-length string. Note: len(rune(alphabet)) must be 58.

func (Alphabet) String

func (alphabet Alphabet) String() string

Alphabet's string representation

type NativeInvoke

type NativeInvoke struct {
	Version         byte
	ContractAddress []byte
	Method          string
	Param           TxState
}

func NewNativeInvoke

func NewNativeInvoke(param TxState) NativeInvoke

func (NativeInvoke) ToBytes

func (ni NativeInvoke) ToBytes() ([]byte, error)

type NativeInvokeV2 added in v1.2.27

type NativeInvokeV2 struct {
	Version         byte
	ContractAddress []byte
	Method          string
	Param           TxStateV2
}

func NewNativeInvokeV2 added in v1.2.27

func NewNativeInvokeV2(param TxStateV2) NativeInvokeV2

func (NativeInvokeV2) ToBytes added in v1.2.27

func (ni NativeInvokeV2) ToBytes() ([]byte, error)

type SigData

type SigData struct {
	Nrequired uint16
	SigPubs   []SigPub
}

type SigPub

type SigPub struct {
	Signature []byte
	PublicKey []byte
}

func SignRawTransactionHash

func SignRawTransactionHash(txHash string, prikey []byte) (*SigPub, error)

type Transaction

type Transaction struct {
	Version    byte
	TxType     byte
	Nonce      []byte
	GasPrice   []byte
	GaseLimit  []byte
	Payer      []byte
	Payload    []byte
	Attributes byte
	SigDatas   []SigData
}

func DecodeRawTransaction

func DecodeRawTransaction(txBytes []byte) (*Transaction, error)

func NewEmptyTransaction

func NewEmptyTransaction(assetType int, txType byte, nonce uint32, gasPrice, gasLimit uint64, payer string, payload []byte) Transaction

func (Transaction) GetGasLimit

func (t Transaction) GetGasLimit() uint64

func (Transaction) GetGasPrice

func (t Transaction) GetGasPrice() uint64

func (Transaction) GetNonce

func (t Transaction) GetNonce() uint32

func (Transaction) GetPayLoad

func (t Transaction) GetPayLoad() string

func (Transaction) GetPayer

func (t Transaction) GetPayer() string

func (Transaction) GetTxType

func (t Transaction) GetTxType() byte

func (Transaction) GetVersion

func (t Transaction) GetVersion() byte

func (Transaction) ToBytes

func (t Transaction) ToBytes() ([]byte, error)

type TxHash

type TxHash struct {
	Hash      string
	Addresses []string
}

func CreateRawTransactionAndHash added in v1.0.15

func CreateRawTransactionAndHash(gasPrice, gasLimit uint64, txState TxState) (string, *TxHash, error)

func CreateRawTransactionAndHashV2 added in v1.2.27

func CreateRawTransactionAndHashV2(gasPrice, gasLimit uint64, txState TxStateV2) (string, *TxHash, error)

func (TxHash) GetTxHashHex

func (tx TxHash) GetTxHashHex() string

type TxState

type TxState struct {
	AssetType int // 'ont' or 'ong'
	Payer     string
	From      string
	To        string
	Amount    uint64
}

type TxStateV2 added in v1.2.27

type TxStateV2 struct {
	AssetType int // 'ont' or 'ong'
	Payer     string
	From      string
	To        string
	Amount    *big.Int
}

Jump to

Keyboard shortcuts

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