mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 18:51:39 +00:00
snative refactor and SNativeTx
This commit is contained in:
@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
ptypes "github.com/tendermint/tendermint/permission/types"
|
||||
)
|
||||
|
||||
type AccountGetter interface {
|
||||
@ -222,3 +223,38 @@ func NewRebondTx(addr []byte, height int) *RebondTx {
|
||||
func (tx *RebondTx) Sign(chainID string, privAccount *acm.PrivAccount) {
|
||||
tx.Signature = privAccount.Sign(chainID, tx).(acm.SignatureEd25519)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// SNativeTx interface for creating tx
|
||||
|
||||
func NewSNativeTx(st AccountGetter, from acm.PubKey, snativeArgs ptypes.SNativeArgs) (*SNativeTx, error) {
|
||||
addr := from.Address()
|
||||
acc := st.GetAccount(addr)
|
||||
if acc == nil {
|
||||
return nil, fmt.Errorf("Invalid address %X from pubkey %X", addr, from)
|
||||
}
|
||||
|
||||
nonce := acc.Sequence + 1
|
||||
return NewSNativeTxWithNonce(from, snativeArgs, nonce), nil
|
||||
}
|
||||
|
||||
func NewSNativeTxWithNonce(from acm.PubKey, snativeArgs ptypes.SNativeArgs, nonce int) *SNativeTx {
|
||||
addr := from.Address()
|
||||
input := &TxInput{
|
||||
Address: addr,
|
||||
Amount: 1, // NOTE: amounts can't be 0 ...
|
||||
Sequence: nonce,
|
||||
Signature: acm.SignatureEd25519{},
|
||||
PubKey: from,
|
||||
}
|
||||
|
||||
return &SNativeTx{
|
||||
Input: input,
|
||||
SNative: snativeArgs,
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *SNativeTx) Sign(chainID string, privAccount *acm.PrivAccount) {
|
||||
tx.Input.PubKey = privAccount.PubKey
|
||||
tx.Input.Signature = privAccount.Sign(chainID, tx)
|
||||
}
|
||||
|
Reference in New Issue
Block a user