bytomTransaction

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

Bytom Transaction Driver

        transaction_test.go测试案例说明
        Test_case1    : 花费单个P2WPKH-UTXO
        Test_case2    : 花费多个P2WPKH-UTXO
        Test_case3    : 多签地址构建验证
        Test_case4    : 花费多签掉UTXO

当前支持

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

        P2WPKH
        Multisig

TODO

        智能合约

Documentation

Index

Constants

View Source
const (
	Bech32HRPSegwitMainNet    = "bm"
	Bech32HRPSegwitTestNet    = "tm"
	HashPrefixEntry           = "entryid:"
	HashPrefixOutput          = "output1:"
	HashPrefixSpend           = "spend1:"
	HashPrefixMux             = "mux1:"
	HashPrefixTxheader        = "txheader:"
	DefaultWitnessVersion     = byte(0)
	DefaultSerFlags           = byte(7)
	DefaultTransactionVersion = uint64(1)
	DefaultAssetVersion       = byte(1)
	DefaultOutVersion         = byte(1)
	DefaultVMVersion          = uint64(1)
	Op_true                   = byte(0x51)
	Op_1                      = byte(0x51)
	Op_TxSignHash             = byte(0xAE)
	Op_CheckMultiSig          = byte(0xAD)

	BTMAssetID = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)

Variables

This section is empty.

Functions

func Bech32Decode

func Bech32Decode(bech string) (string, []byte, error)

Decode decodes a bech32 encoded string, returning the human-readable part and the data part excluding the checksum.

func Bech32Encode

func Bech32Encode(hrp string, data []byte) (string, error)

Encode encodes a byte slice into a bech32 string with the human-readable part hrb. Note that the bytes must each encode 5 bits (base32).

func ConvertBits

func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)

ConvertBits converts a byte slice where each byte is encoding fromBits bits, to a byte slice where each byte is encoding toBits bits.

func CreateEmptyRawTransaction

func CreateEmptyRawTransaction(vins []Vin, vouts []Vout, timeRange uint64, isTestNet bool) (string, error)

func CreateMultiSig

func CreateMultiSig(required byte, pubkeys [][]byte, isTestNet bool) (string, string, error)

func InsertSignatureIntoEmptyTransaction

func InsertSignatureIntoEmptyTransaction(txHex string, txHashes []TxHash) (string, error)

func VerifyRawTransaction

func VerifyRawTransaction(txHex string) bool

Types

type MultiTx

type MultiTx struct {
	Pubkey string
	SigPub SigPub
}

type NormalTx

type NormalTx struct {
	Address string
	SigPub  SigPub
}

type SigPub

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

func SignRawTransactionHash

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

type Transaction

type Transaction struct {
	Version   []byte
	TimeRange []byte
	Inputs    []TxIn
	Outputs   []TxOut
}

func DecodeRawTransaction

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

func (*Transaction) GetTimeRange

func (t *Transaction) GetTimeRange() uint64

func (*Transaction) SetTimeRange

func (t *Transaction) SetTimeRange(time uint64)

func (*Transaction) SetTransVersion

func (t *Transaction) SetTransVersion(ver uint64)

type TxHash

type TxHash struct {
	Hash      string
	NRequired byte
	Normal    *NormalTx
	Multi     []MultiTx
}

func CreateRawTransactionHashForSig

func CreateRawTransactionHashForSig(txHex string, isTestNet bool) ([]TxHash, error)

func (TxHash) IsMultiSig

func (th TxHash) IsMultiSig() bool

func (*TxHash) PadMultiSig

func (th *TxHash) PadMultiSig(signScriptHex string) error

type TxIn

type TxIn struct {
	SourceID       []byte
	SourcePosition []byte
	AssetID        []byte
	Amount         []byte
	ControlProgram []byte
	SigPub         *SigPub
	MultiSig       []byte
}

func (TxIn) GetAmount

func (in TxIn) GetAmount() uint64

func (TxIn) GetAssetID

func (in TxIn) GetAssetID() string

func (TxIn) GetControlProgram

func (in TxIn) GetControlProgram() string

func (TxIn) GetSourceID

func (in TxIn) GetSourceID() string

func (TxIn) GetSourcePosition

func (in TxIn) GetSourcePosition() uint64

func (*TxIn) SetAmount

func (in *TxIn) SetAmount(amount uint64)

func (*TxIn) SetAssetID

func (in *TxIn) SetAssetID(hexID string) error

func (*TxIn) SetControlProgram

func (in *TxIn) SetControlProgram(hexProgram string) error

func (*TxIn) SetSourceID

func (in *TxIn) SetSourceID(hexID string) error

func (*TxIn) SetSourcePosition

func (in *TxIn) SetSourcePosition(pos uint64)

type TxOut

type TxOut struct {
	AssetID        []byte
	ControlProgram []byte
	Amount         []byte
}

func (TxOut) GetAmount

func (out TxOut) GetAmount() uint64

func (*TxOut) SetAmount

func (out *TxOut) SetAmount(amount uint64)

func (*TxOut) SetAssetID

func (out *TxOut) SetAssetID()

func (*TxOut) SetControlProgram

func (out *TxOut) SetControlProgram(address string) error

type Vin

type Vin struct {
	SourceID       string
	SourcePosition uint64
	AssetID        string
	Amount         uint64
	ControlProgram string
}

type Vout

type Vout struct {
	Address string
	Amount  uint64
}

Jump to

Keyboard shortcuts

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