transaction

package
v0.0.0-...-e4b14ae Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: LGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IssuanceInputType uint8 = iota
	SpendInputType
	CoinbaseInputType
)
View Source
const (
	SUCCESS = "success"
	FAIL    = "fail"
)
View Source
const (
	MsgNewTx = iota
)

Variables

View Source
var SRCAssetID = &AssetID{
	V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
	V1: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
	V2: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
	V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
}

Functions

func BuildUtxoTemplate

func BuildUtxoTemplate(inputs []InputAndSigInst, outputs []*TxOutput) (*Template, TxData, error)

Build build transactions with template

func TxSign

func TxSign(tpl *Template, xprv chainkd.XPrv, xpub chainkd.XPub) error

Types

type AssetAmount

type AssetAmount struct {
	AssetId *AssetID `protobuf:"bytes,1,opt,name=asset_id,json=assetId" json:"asset_id,omitempty"`
	Amount  uint64   `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"`
}

func (*AssetAmount) Descriptor

func (*AssetAmount) Descriptor() ([]byte, []int)

func (*AssetAmount) GetAmount

func (m *AssetAmount) GetAmount() uint64

func (*AssetAmount) GetAssetId

func (m *AssetAmount) GetAssetId() *AssetID

func (*AssetAmount) ProtoMessage

func (*AssetAmount) ProtoMessage()

func (*AssetAmount) ReadFrom

func (a *AssetAmount) ReadFrom(r *extend.Reader) (err error)

ReadFrom read the AssetAmount from the bytes

func (*AssetAmount) Reset

func (m *AssetAmount) Reset()

func (*AssetAmount) String

func (m *AssetAmount) String() string

func (AssetAmount) WriteTo

func (a AssetAmount) WriteTo(w io.Writer) (int64, error)

WriteTo convert struct to byte and write to io

type AssetID

type AssetID struct {
	V0 uint64 `protobuf:"fixed64,1,opt,name=v0" json:"v0,omitempty"`
	V1 uint64 `protobuf:"fixed64,2,opt,name=v1" json:"v1,omitempty"`
	V2 uint64 `protobuf:"fixed64,3,opt,name=v2" json:"v2,omitempty"`
	V3 uint64 `protobuf:"fixed64,4,opt,name=v3" json:"v3,omitempty"`
}

This message type duplicates Hash, above. One alternative is to embed a Hash inside an AssetID. But it's useful for AssetID to be plain old data (without pointers). Another alternative is use Hash in any protobuf types where an AssetID is called for, but it's preferable to have type safety.

func (AssetID) Bytes

func (a AssetID) Bytes() []byte

Bytes returns the byte representation.

func (*AssetID) Descriptor

func (*AssetID) Descriptor() ([]byte, []int)

func (*AssetID) GetV0

func (m *AssetID) GetV0() uint64

func (*AssetID) GetV1

func (m *AssetID) GetV1() uint64

func (*AssetID) GetV2

func (m *AssetID) GetV2() uint64

func (*AssetID) GetV3

func (m *AssetID) GetV3() uint64

func (*AssetID) ProtoMessage

func (*AssetID) ProtoMessage()

func (*AssetID) ReadFrom

func (a *AssetID) ReadFrom(r io.Reader) (int64, error)

ReadFrom satisfies the io.ReaderFrom interface.

func (*AssetID) Reset

func (m *AssetID) Reset()

func (*AssetID) String

func (m *AssetID) String() string

func (AssetID) WriteTo

func (a AssetID) WriteTo(w io.Writer) (int64, error)

type CoinbaseInput

type CoinbaseInput struct {
	Arbitrary []byte
}

CoinbaseInput records the coinbase message

func (*CoinbaseInput) InputType

func (cb *CoinbaseInput) InputType() uint8

InputType is the interface function for return the input type

type DataWitness

type DataWitness HexBytes

DataWitness used sign transaction

func (DataWitness) MarshalJSON

func (dw DataWitness) MarshalJSON() ([]byte, error)

MarshalJSON marshal DataWitness

type Entry

type Entry interface {
	proto.Message
	// contains filtered or unexported methods
}

Entry is the interface implemented by each addressable unit in a blockchain: transaction components such as spends, issuances, outputs, and retirements (among others), plus blockheaders.

type Hash

type Hash struct {
	V0 uint64 `protobuf:"fixed64,1,opt,name=v0" json:"v0,omitempty"`
	V1 uint64 `protobuf:"fixed64,2,opt,name=v1" json:"v1,omitempty"`
	V2 uint64 `protobuf:"fixed64,3,opt,name=v2" json:"v2,omitempty"`
	V3 uint64 `protobuf:"fixed64,4,opt,name=v3" json:"v3,omitempty"`
}

func EntryID

func EntryID(e Entry) (hash Hash)

func NewHash

func NewHash(b32 [32]byte) (h Hash)

NewHash convert the input byte array to hash

func (Hash) Byte32

func (h Hash) Byte32() (b32 [32]byte)

Byte32 return the byte array representation

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the byte representation

func (*Hash) Descriptor

func (*Hash) Descriptor() ([]byte, []int)

func (*Hash) GetV0

func (m *Hash) GetV0() uint64

func (*Hash) GetV1

func (m *Hash) GetV1() uint64

func (*Hash) GetV2

func (m *Hash) GetV2() uint64

func (*Hash) GetV3

func (m *Hash) GetV3() uint64

func (*Hash) ProtoMessage

func (*Hash) ProtoMessage()

func (*Hash) ReadFrom

func (h *Hash) ReadFrom(r io.Reader) (int64, error)

func (*Hash) Reset

func (m *Hash) Reset()

func (*Hash) String

func (m *Hash) String() string

func (Hash) WriteTo

func (h Hash) WriteTo(w io.Writer) (int64, error)

WriteTo satisfies the io.WriterTo interface.

type HexBytes

type HexBytes []byte

func (HexBytes) MarshalText

func (h HexBytes) MarshalText() ([]byte, error)

func (*HexBytes) UnmarshalText

func (h *HexBytes) UnmarshalText(text []byte) error

type InputAndSigInst

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

func NewInputAndSigInst

func NewInputAndSigInst(input *TxInput, sigInst *SigningInstruction) InputAndSigInst

func UtxoInputs

func UtxoInputs(xpubs []chainkd.XPub, u *UTXO) (InputAndSigInst, error)

UtxoToInputs convert an utxo to the txinput

type Map

type Map []byte

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(text []byte) error

type Mux

type Mux struct {
	Sources             []*ValueSource      `protobuf:"bytes,1,rep,name=sources" json:"sources,omitempty"`
	Program             *Program            `protobuf:"bytes,2,opt,name=program" json:"program,omitempty"`
	WitnessDestinations []*ValueDestination `protobuf:"bytes,3,rep,name=witness_destinations,json=witnessDestinations" json:"witness_destinations,omitempty"`
	WitnessArguments    [][]byte            `protobuf:"bytes,4,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
}

func NewMux

func NewMux(sources []*ValueSource, program *Program) *Mux

NewMux creates a new Mux.

func (*Mux) Descriptor

func (*Mux) Descriptor() ([]byte, []int)

func (*Mux) GetProgram

func (m *Mux) GetProgram() *Program

func (*Mux) GetSources

func (m *Mux) GetSources() []*ValueSource

func (*Mux) GetWitnessArguments

func (m *Mux) GetWitnessArguments() [][]byte

func (*Mux) GetWitnessDestinations

func (m *Mux) GetWitnessDestinations() []*ValueDestination

func (*Mux) ProtoMessage

func (*Mux) ProtoMessage()

func (*Mux) Reset

func (m *Mux) Reset()

func (*Mux) String

func (m *Mux) String() string

type Output

type Output struct {
	Source         *ValueSource `protobuf:"bytes,1,opt,name=source" json:"source,omitempty"`
	ControlProgram *Program     `protobuf:"bytes,2,opt,name=control_program,json=controlProgram" json:"control_program,omitempty"`
	Ordinal        uint64       `protobuf:"varint,3,opt,name=ordinal" json:"ordinal,omitempty"`
}

func NewOutput

func NewOutput(source *ValueSource, controlProgram *Program, ordinal uint64) *Output

NewOutput creates a new Output.

func (*Output) Descriptor

func (*Output) Descriptor() ([]byte, []int)

func (*Output) GetControlProgram

func (m *Output) GetControlProgram() *Program

func (*Output) GetOrdinal

func (m *Output) GetOrdinal() uint64

func (*Output) GetSource

func (m *Output) GetSource() *ValueSource

func (*Output) ProtoMessage

func (*Output) ProtoMessage()

func (*Output) Reset

func (m *Output) Reset()

func (*Output) String

func (m *Output) String() string

type OutputCommitment

type OutputCommitment struct {
	AssetAmount
	VMVersion      uint64
	ControlProgram []byte
}

type Program

type Program struct {
	VmVersion uint64 `protobuf:"varint,1,opt,name=vm_version,json=vmVersion" json:"vm_version,omitempty"`
	Code      []byte `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"`
}

func (*Program) Descriptor

func (*Program) Descriptor() ([]byte, []int)

func (*Program) GetCode

func (m *Program) GetCode() []byte

func (*Program) GetVmVersion

func (m *Program) GetVmVersion() uint64

func (*Program) ProtoMessage

func (*Program) ProtoMessage()

func (*Program) Reset

func (m *Program) Reset()

func (*Program) String

func (m *Program) String() string

type RawTxSigWitness

type RawTxSigWitness struct {
	Quorum int        `json:"quorum"`
	Keys   []keyID    `json:"keys"`
	Sigs   []HexBytes `json:"signatures"`
}

RawTxSigWitness is like SignatureWitness but doesn't involve signature programs.

func (RawTxSigWitness) MarshalJSON

func (sw RawTxSigWitness) MarshalJSON() ([]byte, error)

MarshalJSON convert struct to json

type RawWitness

type RawWitness struct {
	Quorum int    `json:"quorum"`
	Sigs   string `json:"signatures"`
}

type SigningInstruction

type SigningInstruction struct {
	Position          uint32             `json:"position"`
	WitnessComponents []witnessComponent `json:"witness_components,omitempty"`
}

type Spend

type Spend struct {
	SpentOutputId      *Hash             `protobuf:"bytes,1,opt,name=spent_output_id,json=spentOutputId" json:"spent_output_id,omitempty"`
	WitnessDestination *ValueDestination `protobuf:"bytes,2,opt,name=witness_destination,json=witnessDestination" json:"witness_destination,omitempty"`
	WitnessArguments   [][]byte          `protobuf:"bytes,3,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
	Ordinal            uint64            `protobuf:"varint,4,opt,name=ordinal" json:"ordinal,omitempty"`
}

func NewSpend

func NewSpend(spentOutputID *Hash, ordinal uint64) *Spend

NewSpend creates a new Spend.

func (*Spend) Descriptor

func (*Spend) Descriptor() ([]byte, []int)

func (*Spend) GetOrdinal

func (m *Spend) GetOrdinal() uint64

func (*Spend) GetSpentOutputId

func (m *Spend) GetSpentOutputId() *Hash

func (*Spend) GetWitnessArguments

func (m *Spend) GetWitnessArguments() [][]byte

func (*Spend) GetWitnessDestination

func (m *Spend) GetWitnessDestination() *ValueDestination

func (*Spend) ProtoMessage

func (*Spend) ProtoMessage()

func (*Spend) Reset

func (m *Spend) Reset()

func (*Spend) SetDestination

func (s *Spend) SetDestination(id *Hash, val *AssetAmount, pos uint64)

SetDestination will link the spend to the output

func (*Spend) String

func (m *Spend) String() string

type SpendCommitment

type SpendCommitment struct {
	AssetAmount
	SourceID       Hash
	SourcePosition uint64
	VMVersion      uint64
	ControlProgram []byte
}

SpendCommitment contains the commitment data for a transaction output.

type SpendInput

type SpendInput struct {
	SpendCommitmentSuffix []byte   // The unconsumed suffix of the output commitment
	Arguments             [][]byte // Witness
	SpendCommitment
}

SpendInput satisfies the TypedInput interface and represents a spend transaction.

func (*SpendInput) InputType

func (si *SpendInput) InputType() uint8

InputType is the interface function for return the input type.

type Template

type Template struct {
	Transaction         Tx                    `json:"raw_transaction"`
	SigningInstructions []*SigningInstruction `json:"signing_instructions"`

	// AllowAdditional affects whether Sign commits to the tx sighash or
	// to individual details of the tx so far. When true, signatures
	// commit to tx details, and new details may be added but existing
	// ones cannot be changed. When false, signatures commit to the tx
	// as a whole, and any change to the tx invalidates the signature.
	AllowAdditional bool `json:"allow_additional_actions"`
}

Template represents a partially- or fully-signed transaction.

func (*Template) Hash

func (t *Template) Hash(idx uint32) Hash

Hash return sign hash

type Tx

type Tx struct {
	TxData
	TxWrap `json:"-"`
}

Tx holds a transaction along with its hash.

func NewTx

func NewTx(data TxData) Tx

func (*Tx) OutputID

func (tx *Tx) OutputID(outputIndex int) *Hash

OutputID return the hash of the output position

func (*Tx) SetInputArguments

func (tx *Tx) SetInputArguments(n uint32, args [][]byte)

SetInputArguments sets the Arguments field in input n.

func (*Tx) UnmarshalText

func (tx *Tx) UnmarshalText(p []byte) error

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

type TxData

type TxData struct {
	Version        uint64
	SerializedSize uint64
	TimeRange      uint64
	Inputs         []*TxInput
	Outputs        []*TxOutput
}

TxData encodes a transaction in the blockchain.

func (*TxData) MarshalText

func (tx *TxData) MarshalText() ([]byte, error)

MarshalText fulfills the json.Marshaler interface.

func (*TxData) UnmarshalText

func (tx *TxData) UnmarshalText(p []byte) error

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

func (*TxData) WriteTo

func (tx *TxData) WriteTo(w io.Writer) (int64, error)

WriteTo writes tx to w.

type TxFeed

type TxFeed struct {
	ID     string `json:"id,omitempty"`
	Alias  string `json:"alias"`
	Filter string `json:"filter,omitempty"`
	Param  filter `json:"param,omitempty"`
}

TxFeed describe a filter

type TxFeedManager

type TxFeedManager struct {
	DB      database.LDBDatabase
	TxFeeds []*TxFeed
	// contains filtered or unexported fields
}

Tracker filter tracker object.

func NewTxFeedManager

func NewTxFeedManager(db database.LDBDatabase) *TxFeedManager

func (*TxFeedManager) AddTxFeed

func (t *TxFeedManager) AddTxFeed(ctx context.Context, alias string, filter string) error

func (*TxFeedManager) DeleteTxFeed

func (t *TxFeedManager) DeleteTxFeed(ctx context.Context, alias string) error

func (*TxFeedManager) GetTxFeed

func (t *TxFeedManager) GetTxFeed(ctx context.Context, alias string) (*TxFeed, error)

func (*TxFeedManager) Prepare

func (t *TxFeedManager) Prepare(ctx context.Context) error

new or load txfeed from db

type TxHeader

type TxHeader struct {
	Version        uint64  `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
	SerializedSize uint64  `protobuf:"varint,2,opt,name=serialized_size,json=serializedSize" json:"serialized_size,omitempty"`
	TimeRange      uint64  `protobuf:"varint,3,opt,name=time_range,json=timeRange" json:"time_range,omitempty"`
	ResultIds      []*Hash `protobuf:"bytes,4,rep,name=result_ids,json=resultIds" json:"result_ids,omitempty"`
}

func NewTxHeader

func NewTxHeader(version, serializedSize, timeRange uint64, resultIDs []*Hash) *TxHeader

NewTxHeader creates an new TxHeader.

func (*TxHeader) Descriptor

func (*TxHeader) Descriptor() ([]byte, []int)

func (*TxHeader) GetResultIds

func (m *TxHeader) GetResultIds() []*Hash

func (*TxHeader) GetSerializedSize

func (m *TxHeader) GetSerializedSize() uint64

func (*TxHeader) GetTimeRange

func (m *TxHeader) GetTimeRange() uint64

func (*TxHeader) GetVersion

func (m *TxHeader) GetVersion() uint64

func (*TxHeader) ProtoMessage

func (*TxHeader) ProtoMessage()

func (*TxHeader) Reset

func (m *TxHeader) Reset()

func (*TxHeader) String

func (m *TxHeader) String() string

type TxInput

type TxInput struct {
	AssetVersion     uint64
	CommitmentSuffix []byte
	WitnessSuffix    []byte
	TypedInput
}

TxInput is the top level struct of tx input.

func NewCoinbaseInput

func NewCoinbaseInput(arbitrary []byte) *TxInput

NewCoinbaseInput creates a new coinbase input struct

func NewSpendInput

func NewSpendInput(arguments [][]byte, sourceID Hash, assetID AssetID, amount, sourcePos uint64, controlProgram []byte) *TxInput

NewSpendInput create a new SpendInput struct.

func (*TxInput) SetArguments

func (t *TxInput) SetArguments(args [][]byte)

SetArguments set the args for the input

type TxOutput

type TxOutput struct {
	AssetVersion uint64
	OutputCommitment
	// Unconsumed suffixes of the commitment and witness extensible strings.
	CommitmentSuffix []byte
}

func UtxoOutputs

func UtxoOutputs(assetID AssetID, amount uint64, controlProgram []byte) TxOutput

convert an utxo to th txoutput

type TxPool

type TxPool struct {
	Utxo   map[Hash]Tx
	Tx     Tx
	Weight uint64
	Height uint64
	Fee    uint64
	Mtx    sync.RWMutex
	MsgCh  chan *TxPoolMsg
	Pool   map[Hash]*TxPoolMsg
}

func NewTxPool

func NewTxPool() *TxPool

func (*TxPool) AddRemotes

func (tp *TxPool) AddRemotes([]*types.Transaction) []error

TODO: 有请张先生现身说法

func (*TxPool) AddTransaction

func (tp *TxPool) AddTransaction(tx Tx, fee uint64) error

func (*TxPool) GetMsgCh

func (tp *TxPool) GetMsgCh() <-chan *TxPoolMsg

func (*TxPool) GetTransaction

func (tp *TxPool) GetTransaction(hash *Hash) (*TxPoolMsg, error)

func (*TxPool) Pending

func (tp *TxPool) Pending() (map[common.Address]types.Transactions, error)

func (*TxPool) SubscribeNewTxsEvent

func (tp *TxPool) SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription

func (*TxPool) TxSubmit

func (tp *TxPool) TxSubmit(raw_transaction string) (TxSubmitResponse, error)

type TxPoolMsg

type TxPoolMsg struct {
	Tx      Tx
	Added   time.Time
	Weight  uint64
	Fee     uint64
	MsgType int
}

type TxSubmitResponse

type TxSubmitResponse struct {
	TxID   []byte `json:"tx_id"`
	Status string `json:"status"`
}

type TxWrap

type TxWrap struct {
	*TxHeader
	ID       Hash
	Entries  map[Hash]Entry
	InputIDs []Hash // 1:1 correspondence with TxData.Inputs

	SpentOutputIDs []Hash
	GasInputIDs    []Hash
}

Tx is a wrapper for the entries-based representation of a transaction.

func MapTxWrap

func MapTxWrap(old TxData) TxWrap

func (*TxWrap) Output

func (tx *TxWrap) Output(id Hash) (*Output, error)

Output try to get the output entry by given hash

func (*TxWrap) SigHash

func (tx *TxWrap) SigHash(n uint32) (hash Hash)

SigHash ...

type TypedInput

type TypedInput interface {
	InputType() uint8
}

TypedInput return the txinput type.

type UTXO

type UTXO struct {
	SourceID       Hash
	AssetID        AssetID
	Amount         uint64
	SourcePos      uint64 //utxo sourece index
	ControlProgram []byte //receipt program
	Address        string //receipt address
}

type ValueDestination

type ValueDestination struct {
	Ref      *Hash        `protobuf:"bytes,1,opt,name=ref" json:"ref,omitempty"`
	Value    *AssetAmount `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
	Position uint64       `protobuf:"varint,3,opt,name=position" json:"position,omitempty"`
}

func (*ValueDestination) Descriptor

func (*ValueDestination) Descriptor() ([]byte, []int)

func (*ValueDestination) GetPosition

func (m *ValueDestination) GetPosition() uint64

func (*ValueDestination) GetRef

func (m *ValueDestination) GetRef() *Hash

func (*ValueDestination) GetValue

func (m *ValueDestination) GetValue() *AssetAmount

func (*ValueDestination) ProtoMessage

func (*ValueDestination) ProtoMessage()

func (*ValueDestination) Reset

func (m *ValueDestination) Reset()

func (*ValueDestination) String

func (m *ValueDestination) String() string

type ValueSource

type ValueSource struct {
	Ref      *Hash        `protobuf:"bytes,1,opt,name=ref" json:"ref,omitempty"`
	Value    *AssetAmount `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
	Position uint64       `protobuf:"varint,3,opt,name=position" json:"position,omitempty"`
}

func (*ValueSource) Descriptor

func (*ValueSource) Descriptor() ([]byte, []int)

func (*ValueSource) GetPosition

func (m *ValueSource) GetPosition() uint64

func (*ValueSource) GetRef

func (m *ValueSource) GetRef() *Hash

func (*ValueSource) GetValue

func (m *ValueSource) GetValue() *AssetAmount

func (*ValueSource) ProtoMessage

func (*ValueSource) ProtoMessage()

func (*ValueSource) Reset

func (m *ValueSource) Reset()

func (*ValueSource) String

func (m *ValueSource) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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