transaction

package
v0.0.0-...-c04c664 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeSend     TxType = 0x01
	TypeSellCoin TxType = 0x02
	//TypeSellAllCoin         TxType = 0x03
	TypeBuyCoin TxType = 0x04
	/*TypeCreateCoin          TxType = 0x05
	TypeDeclareCandidacy    TxType = 0x06
	TypeDelegate            TxType = 0x07
	TypeUnbond              TxType = 0x08
	TypeRedeemCheck         TxType = 0x09*/
	TypeSetCandidateOnline  TxType = 0x0A
	TypeSetCandidateOffline TxType = 0x0B
	TypeCreateMultisig      TxType = 0x0C
	TypeMultisend           TxType = 0x0D
	//TypeEditCandidate       TxType = 0x0E
	TypeBtcHeader  TxType = 0x0F
	TypeMntHeader  TxType = 0x10
	TypeBtcDeposit TxType = 0x11
	TypeMntDeposit TxType = 0x12

	TypeBtcSignature TxType = 0x13
	TypeMntSignature TxType = 0x14

	SigTypeSingle SigType = 0x01
	SigTypeMulti  SigType = 0x02
)

Variables

View Source
var (
	CommissionMultiplier = big.NewInt(10e14)
)
View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
View Source
var TxDecoder = Decoder{
	// contains filtered or unexported fields
}

Functions

func EncodeError

func EncodeError(data map[string]string) string

func RecoverPlain

func RecoverPlain(sighash types.Hash, R, S, Vb *big.Int) (types.Address, error)

Types

type BlockHeader

type BlockHeader struct {
	Header types.RlpBtcHeader
	Height uint32
}

type BtcDepositData

type BtcDepositData struct {
	MainnetTxid types.Txid
	Coin        types.CoinSymbol
	Amount      *big.Int
	Owner       types.Address
	BlockHeight uint32
	Proof       [][32]byte

	Vout       uint32
	DataScript []byte
}

func (BtcDepositData) BasicCheck

func (data BtcDepositData) BasicCheck(tx *Transaction, context *state.State) *Response

func (BtcDepositData) Gas

func (data BtcDepositData) Gas() int64

func (BtcDepositData) MarshalJSON

func (data BtcDepositData) MarshalJSON() ([]byte, error)

func (BtcDepositData) Run

func (data BtcDepositData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (BtcDepositData) String

func (data BtcDepositData) String() string

func (BtcDepositData) TotalSpend

func (data BtcDepositData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type BtcHeaderData

type BtcHeaderData struct {
	BlockHeaders []BlockHeader
}

func (BtcHeaderData) BasicCheck

func (data BtcHeaderData) BasicCheck(tx *Transaction, context *state.State) *Response

func (BtcHeaderData) Gas

func (data BtcHeaderData) Gas() int64

func (BtcHeaderData) MarshalJSON

func (data BtcHeaderData) MarshalJSON() ([]byte, error)

func (BtcHeaderData) Run

func (data BtcHeaderData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (BtcHeaderData) String

func (data BtcHeaderData) String() string

func (BtcHeaderData) TotalSpend

func (data BtcHeaderData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type BtcSignatureData

type BtcSignatureData struct {
	Signatures [][64]byte
	PubKey     types.SignatoryPubkey
}

func (BtcSignatureData) BasicCheck

func (data BtcSignatureData) BasicCheck(tx *Transaction, context *state.State) *Response

func (BtcSignatureData) Gas

func (data BtcSignatureData) Gas() int64

func (BtcSignatureData) MarshalJSON

func (data BtcSignatureData) MarshalJSON() ([]byte, error)

func (BtcSignatureData) Run

func (data BtcSignatureData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (BtcSignatureData) String

func (data BtcSignatureData) String() string

func (BtcSignatureData) TotalSpend

func (data BtcSignatureData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type BuyCoinData

type BuyCoinData struct {
	CoinToBuy          types.CoinSymbol
	ValueToBuy         *big.Int
	CoinToSell         types.CoinSymbol
	MaximumValueToSell *big.Int
}

func (BuyCoinData) BasicCheck

func (data BuyCoinData) BasicCheck(tx *Transaction, context *state.State) *Response

func (BuyCoinData) Gas

func (data BuyCoinData) Gas() int64

func (BuyCoinData) MarshalJSON

func (data BuyCoinData) MarshalJSON() ([]byte, error)

func (BuyCoinData) Run

func (data BuyCoinData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (BuyCoinData) String

func (data BuyCoinData) String() string

func (BuyCoinData) TotalSpend

func (data BuyCoinData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends,
	[]Conversion, *big.Int, *Response)

type CandidateTx

type CandidateTx interface {
	GetPubKey() types.Pubkey
}

type Conversion

type Conversion struct {
	FromCoin   types.CoinSymbol
	FromAmount *big.Int
	ToCoin     types.CoinSymbol
	ToAmount   *big.Int
}

type CreateMultisigData

type CreateMultisigData struct {
	Threshold uint
	Weights   []uint
	Addresses []types.Address
}

func (CreateMultisigData) BasicCheck

func (data CreateMultisigData) BasicCheck(tx *Transaction, context *state.State) *Response

func (CreateMultisigData) Gas

func (data CreateMultisigData) Gas() int64

func (CreateMultisigData) MarshalJSON

func (data CreateMultisigData) MarshalJSON() ([]byte, error)

func (CreateMultisigData) Run

func (data CreateMultisigData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (CreateMultisigData) String

func (data CreateMultisigData) String() string

func (CreateMultisigData) TotalSpend

func (data CreateMultisigData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type Data

type Data interface {
	String() string
	Gas() int64
	TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)
	BasicCheck(tx *Transaction, context *state.State) *Response
	Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response
}

type Decoder

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

func (*Decoder) DecodeFromBytes

func (decoder *Decoder) DecodeFromBytes(buf []byte) (*Transaction, error)

func (*Decoder) DecodeFromBytesWithoutSig

func (decoder *Decoder) DecodeFromBytesWithoutSig(buf []byte) (*Transaction, error)

func (*Decoder) RegisterType

func (decoder *Decoder) RegisterType(t TxType, d Data)

type MntDepositData

type MntDepositData struct {
	MainnetTxid types.Txid
	Coin        types.CoinSymbol
	Amount      *big.Int
	Owner       types.Address
	BlockHash   string
	Proof       types.RlpSimpleProof
}

func (MntDepositData) BasicCheck

func (data MntDepositData) BasicCheck(tx *Transaction, context *state.State) *Response

func (MntDepositData) Gas

func (data MntDepositData) Gas() int64

func (MntDepositData) MarshalJSON

func (data MntDepositData) MarshalJSON() ([]byte, error)

func (MntDepositData) Run

func (data MntDepositData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (MntDepositData) String

func (data MntDepositData) String() string

func (MntDepositData) TotalSpend

func (data MntDepositData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type MntHeaderData

type MntHeaderData struct {
	BlockHeader  types.RlpMntSignedHeader
	ValidatorSet types.RlpValidatorSet
}

func (MntHeaderData) BasicCheck

func (data MntHeaderData) BasicCheck(tx *Transaction, context *state.State) *Response

func (MntHeaderData) Gas

func (data MntHeaderData) Gas() int64

func (MntHeaderData) MarshalJSON

func (data MntHeaderData) MarshalJSON() ([]byte, error)

func (MntHeaderData) Run

func (data MntHeaderData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (MntHeaderData) String

func (data MntHeaderData) String() string

func (MntHeaderData) TotalSpend

func (data MntHeaderData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type MntSignatureData

type MntSignatureData struct {
	Signature []byte
}

func (MntSignatureData) BasicCheck

func (data MntSignatureData) BasicCheck(tx *Transaction, context *state.State) *Response

func (MntSignatureData) Gas

func (data MntSignatureData) Gas() int64

func (MntSignatureData) MarshalJSON

func (data MntSignatureData) MarshalJSON() ([]byte, error)

func (MntSignatureData) Run

func (data MntSignatureData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (MntSignatureData) String

func (data MntSignatureData) String() string

func (MntSignatureData) TotalSpend

func (data MntSignatureData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type MultisendData

type MultisendData struct {
	List []MultisendDataItem `json:"list"`
}

func (MultisendData) BasicCheck

func (data MultisendData) BasicCheck(tx *Transaction, context *state.State) *Response

func (MultisendData) Gas

func (data MultisendData) Gas() int64

func (MultisendData) Run

func (data MultisendData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (MultisendData) String

func (data MultisendData) String() string

func (MultisendData) TotalSpend

func (data MultisendData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type MultisendDataItem

type MultisendDataItem struct {
	Coin  types.CoinSymbol
	To    types.Address
	Value *big.Int
}

func (MultisendDataItem) MarshalJSON

func (item MultisendDataItem) MarshalJSON() ([]byte, error)

type RawData

type RawData []byte

type Response

type Response struct {
	Code      uint32    `json:"code,omitempty"`
	Data      []byte    `json:"data,omitempty"`
	Log       string    `json:"log,omitempty"`
	Info      string    `json:"-"`
	GasWanted int64     `json:"gas_wanted,omitempty"`
	GasUsed   int64     `json:"gas_used,omitempty"`
	Tags      []kv.Pair `json:"tags,omitempty"`
	GasPrice  uint32    `json:"gas_price"`
}

func CheckForCoinSupplyOverflow

func CheckForCoinSupplyOverflow(current *big.Int, delta *big.Int, max *big.Int) *Response

func RunTx

func RunTx(context *state.State,
	isCheck bool,
	rawTx []byte,
	rewardPool *big.Int,
	currentBlock uint64,
	currentMempool *sync.Map,
	minGasPrice uint32) Response

type SellCoinData

type SellCoinData struct {
	CoinToSell        types.CoinSymbol
	ValueToSell       *big.Int
	CoinToBuy         types.CoinSymbol
	MinimumValueToBuy *big.Int
}

func (SellCoinData) BasicCheck

func (data SellCoinData) BasicCheck(tx *Transaction, context *state.State) *Response

func (SellCoinData) Gas

func (data SellCoinData) Gas() int64

func (SellCoinData) MarshalJSON

func (data SellCoinData) MarshalJSON() ([]byte, error)

func (SellCoinData) Run

func (data SellCoinData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (SellCoinData) String

func (data SellCoinData) String() string

func (SellCoinData) TotalSpend

func (data SellCoinData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type SendData

type SendData struct {
	Coin  types.CoinSymbol
	To    types.Address
	Value *big.Int
}

func (SendData) BasicCheck

func (data SendData) BasicCheck(tx *Transaction, context *state.State) *Response

func (SendData) Gas

func (data SendData) Gas() int64

func (SendData) MarshalJSON

func (data SendData) MarshalJSON() ([]byte, error)

func (SendData) Run

func (data SendData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (SendData) String

func (data SendData) String() string

func (SendData) TotalSpend

func (data SendData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type SetCandidateOffData

type SetCandidateOffData struct {
	PubKey types.Pubkey `json:"pub_key"`
}

func (SetCandidateOffData) BasicCheck

func (data SetCandidateOffData) BasicCheck(tx *Transaction, context *state.State) *Response

func (SetCandidateOffData) Gas

func (data SetCandidateOffData) Gas() int64

func (SetCandidateOffData) GetPubKey

func (data SetCandidateOffData) GetPubKey() types.Pubkey

func (SetCandidateOffData) MarshalJSON

func (data SetCandidateOffData) MarshalJSON() ([]byte, error)

func (SetCandidateOffData) Run

func (data SetCandidateOffData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (SetCandidateOffData) String

func (data SetCandidateOffData) String() string

func (SetCandidateOffData) TotalSpend

func (data SetCandidateOffData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type SetCandidateOnData

type SetCandidateOnData struct {
	PubKey types.Pubkey
}

func (SetCandidateOnData) BasicCheck

func (data SetCandidateOnData) BasicCheck(tx *Transaction, context *state.State) *Response

func (SetCandidateOnData) Gas

func (data SetCandidateOnData) Gas() int64

func (SetCandidateOnData) GetPubKey

func (data SetCandidateOnData) GetPubKey() types.Pubkey

func (SetCandidateOnData) MarshalJSON

func (data SetCandidateOnData) MarshalJSON() ([]byte, error)

func (SetCandidateOnData) Run

func (data SetCandidateOnData) Run(tx *Transaction, context *state.State, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response

func (SetCandidateOnData) String

func (data SetCandidateOnData) String() string

func (SetCandidateOnData) TotalSpend

func (data SetCandidateOnData) TotalSpend(tx *Transaction, context *state.State) (TotalSpends, []Conversion, *big.Int, *Response)

type SigType

type SigType byte

type Signature

type Signature struct {
	V *big.Int
	R *big.Int
	S *big.Int
}

type SignatureMulti

type SignatureMulti struct {
	Multisig   types.Address
	Signatures []Signature
}

type TotalSpend

type TotalSpend struct {
	Coin  types.CoinSymbol
	Value *big.Int
}

type TotalSpends

type TotalSpends []TotalSpend

func (*TotalSpends) Add

func (tss *TotalSpends) Add(coin types.CoinSymbol, value *big.Int)

type Transaction

type Transaction struct {
	Nonce         uint64
	ChainID       types.ChainID
	GasPrice      uint32
	GasCoin       types.CoinSymbol
	Type          TxType
	Data          RawData
	Payload       []byte
	ServiceData   []byte
	SignatureType SigType
	SignatureData []byte
	// contains filtered or unexported fields
}

func CalcMntTxToSign

func CalcMntTxToSign(mntWithdrawals []types.Withdrawal, coin types.CoinSymbol, nonce uint64) (*Transaction, error)

func DecodeSig

func DecodeSig(tx *Transaction) (*Transaction, error)

func (*Transaction) CommissionInBaseCoin

func (tx *Transaction) CommissionInBaseCoin() *big.Int

func (*Transaction) Gas

func (tx *Transaction) Gas() int64

func (*Transaction) GetDecodedData

func (tx *Transaction) GetDecodedData() Data

func (*Transaction) Hash

func (tx *Transaction) Hash() types.Hash

func (*Transaction) Sender

func (tx *Transaction) Sender() (types.Address, error)

func (*Transaction) Serialize

func (tx *Transaction) Serialize() ([]byte, error)

func (*Transaction) SetDecodedData

func (tx *Transaction) SetDecodedData(data Data)

func (*Transaction) SetMultisigAddress

func (tx *Transaction) SetMultisigAddress(address types.Address)

func (*Transaction) SetSignature

func (tx *Transaction) SetSignature(sig []byte)

func (*Transaction) Sign

func (tx *Transaction) Sign(prv *ecdsa.PrivateKey) error

func (*Transaction) String

func (tx *Transaction) String() string

type TxType

type TxType byte

Jump to

Keyboard shortcuts

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