ontologyTransaction

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

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 (
	MethodTransfer     = "transfer"
	MethodTransferFrom = "transferFrom"
	NativeInvokeName   = "Ontology.Native.Invoke"
)
View Source
const (
	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 CreateEmptyRawTransaction added in v1.0.1

func CreateEmptyRawTransaction(gasPrice, gasLimit uint64, txState TxState) (string, error)

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 InsertSignatureIntoEmptyTransaction added in v1.0.1

func InsertSignatureIntoEmptyTransaction(txHex string, sp SigPub) (string, error)

func VerifyRawTransaction added in v1.0.1

func VerifyRawTransaction(txHex string) bool

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 MultiTx added in v1.0.1

type MultiTx struct {
	Pubkey  string
	SigType byte
	SigPub  SigPub
}

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 NormalTx added in v1.0.1

type NormalTx struct {
	Address string
	SigType byte
	SigPub  SigPub
}

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
	NRequired byte
	Normal    *NormalTx
	Multi     []MultiTx
}

func CreateRawTransactionHashForSig added in v1.0.1

func CreateRawTransactionHashForSig(txHex string) (*TxHash, error)

func (TxHash) GetNormalTxAddress added in v1.0.1

func (tx TxHash) GetNormalTxAddress() string

func (TxHash) GetTxHashHex

func (tx TxHash) GetTxHashHex() string

func (TxHash) IsMultisig added in v1.0.1

func (tx TxHash) IsMultisig() bool

type TxState

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

Jump to

Keyboard shortcuts

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