2017-11-26 14:14:03 -08:00
|
|
|
package types
|
|
|
|
|
2018-01-14 19:49:57 -08:00
|
|
|
import (
|
|
|
|
crypto "github.com/tendermint/go-crypto"
|
|
|
|
)
|
2018-01-06 14:22:21 -08:00
|
|
|
|
2018-02-04 16:59:11 -08:00
|
|
|
// Transactions messages must fulfill the Msg
|
2017-11-26 14:14:03 -08:00
|
|
|
type Msg interface {
|
|
|
|
|
2018-01-12 11:49:53 -08:00
|
|
|
// Return the message type.
|
|
|
|
// Must be alphanumeric or empty.
|
|
|
|
Type() string
|
|
|
|
|
2017-11-26 14:14:03 -08:00
|
|
|
// Get some property of the Msg.
|
|
|
|
Get(key interface{}) (value interface{})
|
|
|
|
|
|
|
|
// Get the canonical byte representation of the Msg.
|
2018-01-10 20:11:44 -08:00
|
|
|
GetSignBytes() []byte
|
2017-11-26 14:14:03 -08:00
|
|
|
|
|
|
|
// ValidateBasic does a simple validation check that
|
|
|
|
// doesn't require access to any other information.
|
2018-01-26 04:19:33 -08:00
|
|
|
ValidateBasic() Error
|
2017-11-26 14:14:03 -08:00
|
|
|
|
|
|
|
// Signers returns the addrs of signers that must sign.
|
|
|
|
// CONTRACT: All signatures must be present to be valid.
|
|
|
|
// CONTRACT: Returns addrs in some deterministic order.
|
2018-01-12 11:49:53 -08:00
|
|
|
GetSigners() []crypto.Address
|
2017-11-26 14:14:03 -08:00
|
|
|
}
|
|
|
|
|
2018-02-04 16:59:11 -08:00
|
|
|
// Transactions objects must fulfill the Tx
|
2017-11-26 14:14:03 -08:00
|
|
|
type Tx interface {
|
2018-01-26 06:22:56 -08:00
|
|
|
|
|
|
|
// Gets the Msg.
|
|
|
|
GetMsg() Msg
|
2017-11-26 14:14:03 -08:00
|
|
|
|
2018-01-12 11:49:53 -08:00
|
|
|
// The address that pays the base fee for this message. The fee is
|
|
|
|
// deducted before the Msg is processed.
|
|
|
|
GetFeePayer() crypto.Address
|
|
|
|
|
2017-11-26 14:14:03 -08:00
|
|
|
// Signatures returns the signature of signers who signed the Msg.
|
|
|
|
// CONTRACT: Length returned is same as length of
|
|
|
|
// pubkeys returned from MsgKeySigners, and the order
|
|
|
|
// matches.
|
|
|
|
// CONTRACT: If the signature is missing (ie the Msg is
|
|
|
|
// invalid), then the corresponding signature is
|
|
|
|
// .Empty().
|
2018-01-12 11:49:53 -08:00
|
|
|
GetSignatures() []StdSignature
|
|
|
|
}
|
|
|
|
|
2018-01-14 19:49:57 -08:00
|
|
|
var _ Tx = (*StdTx)(nil)
|
|
|
|
|
2018-02-17 13:19:34 -08:00
|
|
|
// StdTx is a standard way to wrap a Msg with Signatures.
|
|
|
|
// NOTE: the first signature is the FeePayer (Signatures must not be nil).
|
2018-01-12 11:49:53 -08:00
|
|
|
type StdTx struct {
|
2018-02-23 05:17:07 -08:00
|
|
|
Msg `json:"msg"`
|
|
|
|
Signatures []StdSignature `json:"signatures"`
|
2017-11-26 14:14:03 -08:00
|
|
|
}
|
2018-01-12 11:49:53 -08:00
|
|
|
|
2018-02-17 13:19:34 -08:00
|
|
|
func NewStdTx(msg Msg, sigs []StdSignature) StdTx {
|
|
|
|
return StdTx{
|
|
|
|
Msg: msg,
|
|
|
|
Signatures: sigs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-04 16:59:11 -08:00
|
|
|
//nolint
|
2018-01-26 06:22:56 -08:00
|
|
|
func (tx StdTx) GetMsg() Msg { return tx.Msg }
|
2018-02-17 13:19:34 -08:00
|
|
|
func (tx StdTx) GetFeePayer() crypto.Address { return tx.Signatures[0].PubKey.Address() } // XXX but PubKey is optional!
|
2018-01-14 19:49:57 -08:00
|
|
|
func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures }
|
|
|
|
|
2018-02-04 16:59:11 -08:00
|
|
|
//-------------------------------------
|
|
|
|
|
|
|
|
// Application function variable used to unmarshal transaction bytes
|
2018-01-26 04:19:33 -08:00
|
|
|
type TxDecoder func(txBytes []byte) (Tx, Error)
|