transaction

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 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

	SigTypeSingle SigType = 0x01
	SigTypeMulti  SigType = 0x02
)

Variables

View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
	MaxCoinSupply = big.NewInt(0).Exp(big.NewInt(10), big.NewInt(15+18), nil) // 1,000,000,000,000,000 noahs do
)
View Source
var (
	CommissionMultiplier = big.NewInt(10e14)
)
View Source
var TxDecoder = Decoder{
	// contains filtered or unexported fields
}

Functions

func CheckForCoinSupplyOverflow

func CheckForCoinSupplyOverflow(current *big.Int, delta *big.Int) error

func RecoverPlain

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

Types

type BuyCoinData

type BuyCoinData struct {
	CoinToBuy          types.CoinSymbol `json:"coin_to_buy"`
	ValueToBuy         *big.Int         `json:"value_to_buy"`
	CoinToSell         types.CoinSymbol `json:"coin_to_sell"`
	MaximumValueToSell *big.Int         `json:"maximum_value_to_sell"`
}

func (BuyCoinData) BasicCheck

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

func (BuyCoinData) Gas

func (data BuyCoinData) Gas() int64

func (BuyCoinData) Run

func (data BuyCoinData) Run(tx *Transaction, context *state.StateDB, 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.StateDB) (TotalSpends,
	[]Conversion, *big.Int, *Response)

type CandidateTx

type CandidateTx interface {
	GetPubKey() types.Pubkey
}

type Conversion

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

type CreateCoinData

type CreateCoinData struct {
	Name                 string           `json:"name"`
	Symbol               types.CoinSymbol `json:"symbol"`
	InitialAmount        *big.Int         `json:"initial_amount"`
	InitialReserve       *big.Int         `json:"initial_reserve"`
	ConstantReserveRatio uint             `json:"constant_reserve_ratio"`
}

func (CreateCoinData) BasicCheck

func (data CreateCoinData) BasicCheck(tx *Transaction, context *state.StateDB) *Response

func (CreateCoinData) Gas

func (data CreateCoinData) Gas() int64

func (CreateCoinData) Run

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

func (CreateCoinData) String

func (data CreateCoinData) String() string

func (CreateCoinData) TotalSpend

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

type CreateMultisigData

type CreateMultisigData struct {
	Threshold uint            `json:"threshold"`
	Weights   []uint          `json:"weights"`
	Addresses []types.Address `json:"addresses"`
}

func (CreateMultisigData) BasicCheck

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

func (CreateMultisigData) Gas

func (data CreateMultisigData) Gas() int64

func (CreateMultisigData) Run

func (data CreateMultisigData) Run(tx *Transaction, context *state.StateDB, 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.StateDB) (TotalSpends, []Conversion, *big.Int, *Response)

type Data

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

type DeclareCandidacyData

type DeclareCandidacyData struct {
	Address    types.Address    `json:"address"`
	PubKey     types.Pubkey     `json:"pub_key"`
	Commission uint             `json:"commission"`
	Coin       types.CoinSymbol `json:"coin"`
	Stake      *big.Int         `json:"stake"`
}

func (DeclareCandidacyData) BasicCheck

func (data DeclareCandidacyData) BasicCheck(tx *Transaction, context *state.StateDB) *Response

func (DeclareCandidacyData) Gas

func (data DeclareCandidacyData) Gas() int64

func (DeclareCandidacyData) Run

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

func (DeclareCandidacyData) String

func (data DeclareCandidacyData) String() string

func (DeclareCandidacyData) TotalSpend

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

type Decoder

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

func (*Decoder) DecodeFromBytes

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

func (*Decoder) RegisterType

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

type DelegateData

type DelegateData struct {
	PubKey types.Pubkey     `json:"pub_key"`
	Coin   types.CoinSymbol `json:"coin"`
	Value  *big.Int         `json:"value"`
}

func (DelegateData) BasicCheck

func (data DelegateData) BasicCheck(tx *Transaction, context *state.StateDB) *Response

func (DelegateData) Gas

func (data DelegateData) Gas() int64

func (DelegateData) Run

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

func (DelegateData) String

func (data DelegateData) String() string

func (DelegateData) TotalSpend

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

type EditCandidateData

type EditCandidateData struct {
	PubKey        types.Pubkey  `json:"pub_key"`
	RewardAddress types.Address `json:"reward_address"`
	OwnerAddress  types.Address `json:"owner_address"`
}

func (EditCandidateData) BasicCheck

func (data EditCandidateData) BasicCheck(tx *Transaction, context *state.StateDB) *Response

func (EditCandidateData) Gas

func (data EditCandidateData) Gas() int64

func (EditCandidateData) GetPubKey

func (data EditCandidateData) GetPubKey() types.Pubkey

func (EditCandidateData) Run

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

func (EditCandidateData) String

func (data EditCandidateData) String() string

func (EditCandidateData) TotalSpend

func (data EditCandidateData) TotalSpend(tx *Transaction, context *state.StateDB) (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.StateDB) *Response

func (MultisendData) Gas

func (data MultisendData) Gas() int64

func (MultisendData) Run

func (data MultisendData) Run(tx *Transaction, context *state.StateDB, 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.StateDB) (TotalSpends, []Conversion, *big.Int, *Response)

type MultisendDataItem

type MultisendDataItem struct {
	Coin  types.CoinSymbol `json:"coin"`
	To    types.Address    `json:"to"`
	Value *big.Int         `json:"value"`
}

type RawData

type RawData []byte

type RedeemCheckData

type RedeemCheckData struct {
	RawCheck []byte   `json:"raw_check"`
	Proof    [65]byte `json:"proof"`
}

func (RedeemCheckData) BasicCheck

func (data RedeemCheckData) BasicCheck(tx *Transaction, context *state.StateDB) *Response

func (RedeemCheckData) CommissionInBaseCoin

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

func (RedeemCheckData) Gas

func (data RedeemCheckData) Gas() int64

func (RedeemCheckData) Run

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

func (RedeemCheckData) String

func (data RedeemCheckData) String() string

func (RedeemCheckData) TotalSpend

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

type Response

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

func RunTx

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

type SellAllCoinData

type SellAllCoinData struct {
	CoinToSell        types.CoinSymbol `json:"coin_to_sell"`
	CoinToBuy         types.CoinSymbol `json:"coin_to_buy"`
	MinimumValueToBuy *big.Int         `json:"minimum_value_to_buy"`
}

func (SellAllCoinData) BasicCheck

func (data SellAllCoinData) BasicCheck(tx *Transaction, context *state.StateDB) *Response

func (SellAllCoinData) Gas

func (data SellAllCoinData) Gas() int64

func (SellAllCoinData) Run

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

func (SellAllCoinData) String

func (data SellAllCoinData) String() string

func (SellAllCoinData) TotalSpend

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

type SellCoinData

type SellCoinData struct {
	CoinToSell        types.CoinSymbol `json:"coin_to_sell"`
	ValueToSell       *big.Int         `json:"value_to_sell"`
	CoinToBuy         types.CoinSymbol `json:"coin_to_buy"`
	MinimumValueToBuy *big.Int         `json:"minimum_value_to_buy"`
}

func (SellCoinData) BasicCheck

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

func (SellCoinData) Gas

func (data SellCoinData) Gas() int64

func (SellCoinData) Run

func (data SellCoinData) Run(tx *Transaction, context *state.StateDB, 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.StateDB) (TotalSpends, []Conversion, *big.Int, *Response)

type SendData

type SendData struct {
	Coin  types.CoinSymbol `json:"coin"`
	To    types.Address    `json:"to"`
	Value *big.Int         `json:"value"`
}

func (SendData) BasicCheck

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

func (SendData) Gas

func (data SendData) Gas() int64

func (SendData) Run

func (data SendData) Run(tx *Transaction, context *state.StateDB, 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.StateDB) (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.StateDB) *Response

func (SetCandidateOffData) Gas

func (data SetCandidateOffData) Gas() int64

func (SetCandidateOffData) GetPubKey

func (data SetCandidateOffData) GetPubKey() types.Pubkey

func (SetCandidateOffData) Run

func (data SetCandidateOffData) Run(tx *Transaction, context *state.StateDB, 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.StateDB) (TotalSpends, []Conversion, *big.Int, *Response)

type SetCandidateOnData

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

func (SetCandidateOnData) BasicCheck

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

func (SetCandidateOnData) Gas

func (data SetCandidateOnData) Gas() int64

func (SetCandidateOnData) GetPubKey

func (data SetCandidateOnData) GetPubKey() types.Pubkey

func (SetCandidateOnData) Run

func (data SetCandidateOnData) Run(tx *Transaction, context *state.StateDB, 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.StateDB) (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 (*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

type UnbondData

type UnbondData struct {
	PubKey types.Pubkey     `json:"pub_key"`
	Coin   types.CoinSymbol `json:"coin"`
	Value  *big.Int         `json:"value"`
}

func (UnbondData) BasicCheck

func (data UnbondData) BasicCheck(tx *Transaction, context *state.StateDB) *Response

func (UnbondData) Gas

func (data UnbondData) Gas() int64

func (UnbondData) Run

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

func (UnbondData) String

func (data UnbondData) String() string

func (UnbondData) TotalSpend

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

Jump to

Keyboard shortcuts

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