Documentation ¶
Overview ¶
Package transactions contains all the logic for creating and validating transactions and call messages.
Index ¶
- Constants
- Variables
- type Action
- type ActionCall
- type ActionExecution
- type Attribute
- type AuxiliaryType
- type CallMessage
- type CallMessageBody
- type Column
- type DropSchema
- type Extension
- type ExtensionConfig
- type ForeignKey
- type ForeignKeyAction
- type Index
- type MutabilityType
- type Payload
- type PayloadType
- type RawValue
- type Schema
- type SignedMsgSerializationType
- type Table
- type TcTxQueryResponse
- type Transaction
- type TransactionBody
- type TransactionResult
- type Transfer
- type TxCode
- type TxHash
- type ValidatorApprove
- type ValidatorJoin
- type ValidatorLeave
- type ValidatorRemove
- type ValidatorVoteBodies
- type ValidatorVoteIDs
Constants ¶
const (
// EIP712DomainTypeName TODO: to test if we can change this
EIP712DomainTypeName = "EIP712Domain"
)
const MsgDescriptionMaxLength = 200
MsgDescriptionMaxLength is the max length of Description filed in TransactionBody and CallMessageBody
Variables ¶
var ( // ErrTxNotFound is indicates when the a transaction was not found in the // nodes blocks or mempool. ErrTxNotFound = errors.New("transaction not found") ErrWrongChain = errors.New("wrong chain ID") ErrInvalidNonce = errors.New("invalid nonce") ErrInvalidAmount = errors.New("invalid amount") ErrInsufficientBalance = errors.New("insufficient balance") )
var EIP712TypedDataMessage = []gethTypes.Type{
{Name: "payload_type", Type: "string"},
{Name: "payload_digest", Type: "string"},
{Name: "fee", Type: "string"},
{Name: "nonce", Type: "string"},
{Name: "chainID", Type: "string"},
}
EIP712TypedDataMessage represents the primary type for EIP712 data
var EIP712TypedDomain = []gethTypes.Type{
{Name: "name", Type: "string"},
{Name: "version", Type: "string"},
{Name: "salt", Type: "string"},
}
EIP712TypedDomain represents the domain separator for EIP712
var TxSignerNetwork = []byte("network")
TxSignerNetwork is used to identify when a transaction has originated from general network consensus (via vote extensions), rather than from an individual user / validator. It replaces the Sender field in the Transaction struct.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { Name string `json:"name"` // Annotations are the annotations that the action has. It's optional. Annotations []string `json:"annotations,omitempty"` Inputs []string `json:"inputs,omitempty"` // Mutability could be empty if the abi is generated by legacy version of kuneiform, // default to "update" for backward compatibility Mutability string `json:"mutability,omitempty"` // Auxiliaries are the auxiliary types that are required for the action, specifying extra characteristics of the action Auxiliaries []string `json:"auxiliaries,omitempty"` Public bool `json:"public,omitempty"` Statements []string `json:"statements,omitempty"` }
type ActionCall ¶
type ActionCall struct { DBID string Action string Arguments []string // NilArg indicates for each of the elements in Arguments if the value is // nil rather than just empty. NilArg []bool `rlp:"optional"` }
ActionCall is the payload that is used to call an action
func (*ActionCall) MarshalBinary ¶
func (a *ActionCall) MarshalBinary() (serialize.SerializedData, error)
func (*ActionCall) Type ¶
func (a *ActionCall) Type() PayloadType
func (*ActionCall) UnmarshalBinary ¶
func (a *ActionCall) UnmarshalBinary(b serialize.SerializedData) error
type ActionExecution ¶
type ActionExecution struct { DBID string Action string Arguments [][]string // NilArg indicates for each of the elements in Arguments if the value is // nil rather than just empty. NilArg [][]bool `rlp:"optional"` }
ActionExecution is the payload that is used to execute an action
func (*ActionExecution) MarshalBinary ¶
func (a *ActionExecution) MarshalBinary() (serialize.SerializedData, error)
func (*ActionExecution) Type ¶
func (a *ActionExecution) Type() PayloadType
func (*ActionExecution) UnmarshalBinary ¶
func (a *ActionExecution) UnmarshalBinary(b serialize.SerializedData) error
type AuxiliaryType ¶
type AuxiliaryType string
AuxiliaryType is the type of auxiliary
const ( // AuxiliaryTypeMustSign is used to specify that an action need signature, it is used for `view` action. AuxiliaryTypeMustSign AuxiliaryType = "mustsign" // AuxiliaryTypeOwner is used to specify that an action caller must be the owner of the database. AuxiliaryTypeOwner AuxiliaryType = "owner" )
func (AuxiliaryType) String ¶
func (t AuxiliaryType) String() string
type CallMessage ¶
type CallMessage struct { // Body is the body of the actual message Body *CallMessageBody // the type of authenticator, which will be used to derive 'identifier' // from the 'sender` AuthType string // Sender is the public key of the sender Sender []byte }
CallMessage represents a message could be used to call an action. This is meant to work like transactions.Transaction, except that it is not a transaction.
func CreateCallMessage ¶
func CreateCallMessage(payload *ActionCall) (*CallMessage, error)
CreateCallMessage creates a new call message from a ActionCall payload.
type CallMessageBody ¶
type CallMessageBody struct { // Payload is the payload of the message, it is RLP encoded Payload serialize.SerializedData }
CallMessageBody is the body of a call message.
type DropSchema ¶
type DropSchema struct {
DBID string
}
DropSchema is the payload that is used to drop a schema
func (*DropSchema) MarshalBinary ¶
func (s *DropSchema) MarshalBinary() (serialize.SerializedData, error)
func (*DropSchema) Type ¶
func (s *DropSchema) Type() PayloadType
func (*DropSchema) UnmarshalBinary ¶
func (s *DropSchema) UnmarshalBinary(b serialize.SerializedData) error
type Extension ¶
type Extension struct { Name string `json:"name"` Config []*ExtensionConfig `json:"config"` Alias string `json:"alias"` }
type ExtensionConfig ¶
type ForeignKey ¶
type ForeignKey struct { // ChildKeys are the columns that are referencing another. // For example, in FOREIGN KEY (a) REFERENCES tbl2(b), "a" is the child key ChildKeys []string `json:"child_keys"` // ParentKeys are the columns that are being referred to. // For example, in FOREIGN KEY (a) REFERENCES tbl2(b), "tbl2.b" is the parent key ParentKeys []string `json:"parent_keys"` // ParentTable is the table that holds the parent columns. // For example, in FOREIGN KEY (a) REFERENCES tbl2(b), "tbl2.b" is the parent table ParentTable string `json:"parent_table"` // Action refers to what the foreign key should do when the parent is altered. // This is NOT the same as a database action; // however sqlite's docs refer to these as actions, // so we should be consistent with that. // For example, ON DELETE CASCADE is a foreign key action Actions []*ForeignKeyAction `json:"actions"` }
type ForeignKeyAction ¶
type ForeignKeyAction struct { // On can be either "UPDATE" or "DELETE" On string `json:"on"` // Do specifies what a foreign key action should do Do string `json:"do"` }
ForeignKeyAction is used to specify what should occur if a parent key is updated or deleted
type MutabilityType ¶
type MutabilityType string
MutabilityType is the type of mutability
const ( MutabilityUpdate MutabilityType = "update" MutabilityView MutabilityType = "view" )
func (MutabilityType) String ¶
func (t MutabilityType) String() string
type Payload ¶
type Payload interface { MarshalBinary() (serialize.SerializedData, error) UnmarshalBinary(serialize.SerializedData) error Type() PayloadType }
Payload is the interface that all payloads must implement Implementations should use Kwil's serialization package to encode and decode themselves
type PayloadType ¶
type PayloadType string
PayloadType is the type of payload
const ( PayloadTypeDeploySchema PayloadType = "deploy_schema" PayloadTypeDropSchema PayloadType = "drop_schema" PayloadTypeExecuteAction PayloadType = "execute_action" PayloadTypeCallAction PayloadType = "call_action" PayloadTypeTransfer PayloadType = "transfer" PayloadTypeValidatorJoin PayloadType = "validator_join" PayloadTypeValidatorLeave PayloadType = "validator_leave" PayloadTypeValidatorRemove PayloadType = "validator_remove" PayloadTypeValidatorApprove PayloadType = "validator_approve" PayloadTypeValidatorVoteIDs PayloadType = "validator_vote_ids" PayloadTypeValidatorVoteBodies PayloadType = "validator_vote_bodies" )
func (PayloadType) String ¶
func (p PayloadType) String() string
func (PayloadType) Valid ¶
func (p PayloadType) Valid() bool
type RawValue ¶
RawValue is used to swallow RLP data, and is intended to be used with "tail" tagged rlp struct fields at the end of a struct, to provide forward compatibility.
type Schema ¶
type Schema struct { Owner []byte `json:"owner"` Name string `json:"name"` Tables []*Table `json:"tables"` Actions []*Action `json:"actions"` Extensions []*Extension `json:"extensions"` }
Schema is the payload that is used to deploy a schema
func (*Schema) MarshalBinary ¶
func (s *Schema) MarshalBinary() (serialize.SerializedData, error)
func (*Schema) Type ¶
func (s *Schema) Type() PayloadType
func (*Schema) UnmarshalBinary ¶
func (s *Schema) UnmarshalBinary(b serialize.SerializedData) error
type SignedMsgSerializationType ¶
type SignedMsgSerializationType string
SignedMsgSerializationType is the type of serialization performed on a transaction body(in signing and verification) The main reason we need this is that this type could also to used as the 'version' of the serialization. For now, i think it's a bit redundant. To sign a transaction, you need three types:
- the type of payload
- the type of serialization
- the type of signature(e.g. signer)
But in the future, take eth signing for example, we might change the `signedMsgTmpl` for personal_sign, or `domain` for eip712, this type could be used to distinguish the different versions.
NOTE: The valid combination of 2.) and 3.) are:
- `SignedMsgConcat` + `PersonalSigner/CometBftSigner/NearSigner`, which is the default for the `client` package
- `SignedMsgEip712` + `Eip712Signer`
const ( // SignedMsgConcat is a human-readable serialization of the transaction body // it needs a signer that signs SignedMsgConcat SignedMsgSerializationType = "concat" // SignedMsgEip712 is specific serialization for EIP712 SignedMsgEip712 SignedMsgSerializationType = "eip712" // DefaultSignedMsgSerType is the default serialization type // It's `concat` for now, since it's the only one known works for every signer DefaultSignedMsgSerType = SignedMsgConcat )
func (SignedMsgSerializationType) String ¶
func (s SignedMsgSerializationType) String() string
type Table ¶
type Table struct { Name string `json:"name"` Columns []*Column `json:"columns,omitempty"` Indexes []*Index `json:"indexes,omitempty"` ForeignKeys []*ForeignKey `json:"foreign_keys,omitempty"` }
type TcTxQueryResponse ¶
type TcTxQueryResponse struct { Hash []byte `json:"hash,omitempty"` Height int64 `json:"height,omitempty"` Tx Transaction `json:"tx"` TxResult TransactionResult `json:"tx_result"` }
TcTxQueryResponse is the response of a transaction query NOTE: not `txpb.TxQueryResponse` so TransportClient only use our brewed type same as `TransactionResult`
type Transaction ¶
type Transaction struct { // Signature is the signature of the transaction. Signature *auth.Signature // Body is the body of the transaction. It gets serialized and signed. Body *TransactionBody // Serialization is the serialization performed on `Body` // in order to generate the message that being signed. Serialization SignedMsgSerializationType // Sender is the user identifier, which is generally an address but may be // a public key of the sender. Sender []byte // TODO: this field isn't actually used. internally, we always use the signer's identity }
func CreateTransaction ¶
func CreateTransaction(contents Payload, chainID string, nonce uint64) (*Transaction, error)
CreateTransaction creates a new unsigned transaction.
func (*Transaction) MarshalBinary ¶
func (t *Transaction) MarshalBinary() (serialize.SerializedData, error)
MarshalBinary produces the full binary serialization of the transaction, which is the form used in p2p messaging and blockchain storage.
func (*Transaction) SerializeMsg ¶
func (t *Transaction) SerializeMsg() ([]byte, error)
SerializeMsg produces the serialization of the transaction that is to be used in both signing and verification of transaction.
func (*Transaction) Sign ¶
func (t *Transaction) Sign(signer auth.Signer) error
Sign signs transaction body with given signer. It will serialize the transaction body first and sign it.
func (*Transaction) UnmarshalBinary ¶
func (t *Transaction) UnmarshalBinary(data serialize.SerializedData) error
type TransactionBody ¶
type TransactionBody struct { // Description is a human-readable description of the transaction Description string // Payload is the raw bytes of the payload data, it is RLP encoded Payload serialize.SerializedData // PayloadType is the type of the payload // This can be used to determine how to decode the payload PayloadType PayloadType // Fee is the fee the sender is willing to pay for the transaction Fee *big.Int // Nonce is the next nonce of the sender Nonce uint64 // ChainID identifies the Kwil chain for which the transaction is intended. // Alternatively, this could be withheld from the TransactionBody and passed // as an argument to SerializeMsg, as is seen in ethereum signers and even // CometBFT's SignProposal method. However, the full transaction // serialization must include it anyway since it passes through the // consensus engine and p2p systems as an opaque blob that must be // unmarshalled with the chain ID in Kwil blockchain application. ChainID string }
TransactionBody is the body of a transaction that gets included in the signature NOTE: rlp encoding will preserve the order of the fields
func (*TransactionBody) MarshalBinary ¶
func (t *TransactionBody) MarshalBinary() ([]byte, error)
func (*TransactionBody) SerializeMsg ¶
func (t *TransactionBody) SerializeMsg(mst SignedMsgSerializationType) ([]byte, error)
SerializeMsg prepares a message for signing or verification using a certain message construction format. This is done since a Kwil transaction is foreign to wallets, and it is signed as a message, not a transaction that is native to the wallet. As such we define conventions for constructing user-friendly messages. The Kwil frontend SDKs must implement these serialization schemes.
type TransactionResult ¶
type TransactionResult struct { Code uint32 `json:"code"` Log string `json:"log"` GasUsed int64 `json:"gas_used"` GasWanted int64 `json:"gas_wanted"` Data []byte `json:"data,omitempty"` Events [][]byte `json:"events,omitempty"` }
TransactionResult is the result of a transaction execution on chain
type Transfer ¶
type Transfer struct { To []byte `json:"to"` // to be string as user identifier Amount string `json:"amount"` // big.Int }
func (*Transfer) MarshalBinary ¶
func (*Transfer) Type ¶
func (v *Transfer) Type() PayloadType
func (*Transfer) UnmarshalBinary ¶
type TxCode ¶
type TxCode uint32
const ( CodeOk TxCode = 0 CodeEncodingError TxCode = 1 CodeInvalidTxType TxCode = 2 CodeInvalidSignature TxCode = 3 CodeInvalidNonce TxCode = 4 CodeWrongChain TxCode = 5 CodeInsufficientBalance TxCode = 6 CodeInsufficientFee TxCode = 7 CodeInvalidAmount TxCode = 8 CodeInvalidSender TxCode = 9 CodeUnknownError TxCode = math.MaxUint32 )
type TxHash ¶
type TxHash []byte
TxHash is the hash of a transaction that could be used to query the transaction
type ValidatorApprove ¶
type ValidatorApprove struct {
Candidate []byte
}
func (*ValidatorApprove) MarshalBinary ¶
func (v *ValidatorApprove) MarshalBinary() ([]byte, error)
func (*ValidatorApprove) Type ¶
func (v *ValidatorApprove) Type() PayloadType
func (*ValidatorApprove) UnmarshalBinary ¶
func (v *ValidatorApprove) UnmarshalBinary(b []byte) error
type ValidatorJoin ¶
type ValidatorJoin struct {
Power uint64
}
func (*ValidatorJoin) MarshalBinary ¶
func (v *ValidatorJoin) MarshalBinary() ([]byte, error)
func (*ValidatorJoin) Type ¶
func (v *ValidatorJoin) Type() PayloadType
func (*ValidatorJoin) UnmarshalBinary ¶
func (v *ValidatorJoin) UnmarshalBinary(b []byte) error
type ValidatorLeave ¶
type ValidatorLeave struct{}
func (*ValidatorLeave) MarshalBinary ¶
func (v *ValidatorLeave) MarshalBinary() ([]byte, error)
func (*ValidatorLeave) Type ¶
func (v *ValidatorLeave) Type() PayloadType
func (*ValidatorLeave) UnmarshalBinary ¶
func (v *ValidatorLeave) UnmarshalBinary(b []byte) error
type ValidatorRemove ¶
type ValidatorRemove struct {
Validator []byte
}
func (*ValidatorRemove) MarshalBinary ¶
func (v *ValidatorRemove) MarshalBinary() ([]byte, error)
func (*ValidatorRemove) Type ¶
func (v *ValidatorRemove) Type() PayloadType
func (*ValidatorRemove) UnmarshalBinary ¶
func (v *ValidatorRemove) UnmarshalBinary(b []byte) error
type ValidatorVoteBodies ¶
type ValidatorVoteBodies struct { // Events is an array of the full resolution bodies the caller is voting for. Events []*types.VotableEvent }
ValidatorVoteBodies is a payload for submitting the full vote bodies for any resolution.
func (*ValidatorVoteBodies) MarshalBinary ¶
func (v *ValidatorVoteBodies) MarshalBinary() (serialize.SerializedData, error)
func (*ValidatorVoteBodies) Type ¶
func (v *ValidatorVoteBodies) Type() PayloadType
func (*ValidatorVoteBodies) UnmarshalBinary ¶
func (v *ValidatorVoteBodies) UnmarshalBinary(p0 serialize.SerializedData) error
type ValidatorVoteIDs ¶
type ValidatorVoteIDs struct { // ResolutionIDs is an array of all resolution IDs the caller is approving. ResolutionIDs []types.UUID }
ValidatorVoteIDs is a payload for submitting approvals for any pending resolution, by ID.
func (*ValidatorVoteIDs) MarshalBinary ¶
func (v *ValidatorVoteIDs) MarshalBinary() (serialize.SerializedData, error)
func (*ValidatorVoteIDs) Type ¶
func (v *ValidatorVoteIDs) Type() PayloadType
func (*ValidatorVoteIDs) UnmarshalBinary ¶
func (v *ValidatorVoteIDs) UnmarshalBinary(p0 serialize.SerializedData) error