mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-27 21:21:20 +00:00
commit
c6841e8499
2
Makefile
2
Makefile
@ -27,6 +27,8 @@ build_race:
|
||||
go build -race -o build/logjack github.com/tendermint/tendermint/cmd/logjack
|
||||
|
||||
test: build
|
||||
-rm -rf ~/.tendermint_test_bak
|
||||
-mv ~/.tendermint_test ~/.tendermint_test_bak
|
||||
go test github.com/tendermint/tendermint/...
|
||||
|
||||
draw_deps:
|
||||
|
@ -2,7 +2,6 @@ package account
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
|
||||
@ -12,7 +11,6 @@ import (
|
||||
|
||||
// PubKey is part of Account and Validator.
|
||||
type PubKey interface {
|
||||
IsNil() bool
|
||||
Address() []byte
|
||||
VerifyBytes(msg []byte, sig Signature) bool
|
||||
}
|
||||
@ -33,8 +31,6 @@ var _ = binary.RegisterInterface(
|
||||
// Implements PubKey
|
||||
type PubKeyEd25519 [32]byte
|
||||
|
||||
func (pubKey PubKeyEd25519) IsNil() bool { return false }
|
||||
|
||||
// TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.)
|
||||
func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey[:]) }
|
||||
|
||||
@ -60,14 +56,6 @@ func (pubKey PubKeyEd25519) ToCurve25519() *[32]byte {
|
||||
return keyCurve25519
|
||||
}
|
||||
|
||||
// redundant: compiler does it for us
|
||||
func (pubKey PubKeyEd25519) ValidateBasic() error {
|
||||
if len(pubKey) != ed25519.PublicKeySize {
|
||||
return errors.New("Invalid PubKeyEd25519 key size")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pubKey PubKeyEd25519) String() string {
|
||||
return Fmt("PubKeyEd25519{%X}", pubKey[:])
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
|
||||
// Signature is a part of Txs and consensus Votes.
|
||||
type Signature interface {
|
||||
IsZero() bool
|
||||
String() string
|
||||
}
|
||||
|
||||
// Types of Signature implementations
|
||||
@ -27,8 +29,6 @@ var _ = binary.RegisterInterface(
|
||||
// Implements Signature
|
||||
type SignatureEd25519 [64]byte
|
||||
|
||||
func (sig SignatureEd25519) IsNil() bool { return false }
|
||||
|
||||
func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
|
||||
|
||||
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
|
||||
|
@ -670,7 +670,6 @@ func readReflectJSON(rv reflect.Value, rt reflect.Type, o interface{}, err *erro
|
||||
return
|
||||
}
|
||||
log.Debug("Read bytearray", "bytes", buf)
|
||||
|
||||
reflect.Copy(rv, reflect.ValueOf(buf))
|
||||
} else {
|
||||
oSlice, ok := o.([]interface{})
|
||||
|
@ -16,40 +16,6 @@ type SimpleStruct struct {
|
||||
Time time.Time
|
||||
}
|
||||
|
||||
type SimpleArray [5]byte
|
||||
|
||||
func TestSimpleArray(t *testing.T) {
|
||||
var foo SimpleArray
|
||||
|
||||
// Type of pointer to array
|
||||
rt := reflect.TypeOf(&foo)
|
||||
fmt.Printf("rt: %v\n", rt)
|
||||
|
||||
// Type of array itself.
|
||||
// NOTE: normally this is acquired through other means
|
||||
// like introspecting on method signatures, or struct fields.
|
||||
rte := rt.Elem()
|
||||
fmt.Printf("rte: %v\n", rte)
|
||||
|
||||
// Get a new pointer to the array
|
||||
// NOTE: calling .Interface() is to get the actual value,
|
||||
// instead of reflection values.
|
||||
ptr := reflect.New(rte).Interface()
|
||||
fmt.Printf("ptr: %v", ptr)
|
||||
|
||||
// Make a simple int aray
|
||||
fooArray := SimpleArray([5]byte{1, 10, 50, 100, 200})
|
||||
fooBytes := BinaryBytes(fooArray)
|
||||
fooReader := bytes.NewReader(fooBytes)
|
||||
|
||||
// Now you can read it.
|
||||
n, err := new(int64), new(error)
|
||||
it := ReadBinary(foo, fooReader, n, err)
|
||||
fmt.Println(it, reflect.TypeOf(it))
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
type Animal interface{}
|
||||
|
||||
const (
|
||||
@ -502,3 +468,40 @@ func TestBadAlloc(t *testing.T) {
|
||||
res := ReadBinary(instance, b, n, err)
|
||||
fmt.Println(res, *err)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type SimpleArray [5]byte
|
||||
|
||||
func TestSimpleArray(t *testing.T) {
|
||||
var foo SimpleArray
|
||||
|
||||
// Type of pointer to array
|
||||
rt := reflect.TypeOf(&foo)
|
||||
fmt.Printf("rt: %v\n", rt) // *binary.SimpleArray
|
||||
|
||||
// Type of array itself.
|
||||
// NOTE: normally this is acquired through other means
|
||||
// like introspecting on method signatures, or struct fields.
|
||||
rte := rt.Elem()
|
||||
fmt.Printf("rte: %v\n", rte) // binary.SimpleArray
|
||||
|
||||
// Get a new pointer to the array
|
||||
// NOTE: calling .Interface() is to get the actual value,
|
||||
// instead of reflection values.
|
||||
ptr := reflect.New(rte).Interface()
|
||||
fmt.Printf("ptr: %v\n", ptr) // &[0 0 0 0 0]
|
||||
|
||||
// Make a simple int aray
|
||||
fooArray := SimpleArray([5]byte{1, 10, 50, 100, 200})
|
||||
fooBytes := BinaryBytes(fooArray)
|
||||
fooReader := bytes.NewReader(fooBytes)
|
||||
|
||||
// Now you can read it.
|
||||
n, err := new(int64), new(error)
|
||||
it := ReadBinary(foo, fooReader, n, err).(SimpleArray)
|
||||
|
||||
if !bytes.Equal(it[:], fooArray[:]) {
|
||||
t.Errorf("Expected %v but got %v", fooArray, it)
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
)
|
||||
|
||||
func gen_account() {
|
||||
privAccount := account.GenPrivAccount()
|
||||
privAccount := acm.GenPrivAccount()
|
||||
privAccountJSONBytes := binary.JSONBytes(privAccount)
|
||||
fmt.Printf(`Generated a new account!
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
dbm "github.com/tendermint/tendermint/db"
|
||||
@ -54,13 +54,13 @@ func gen_tx() {
|
||||
// Get source pubkey
|
||||
srcPubKeyBytes := getByteSliceFromHex("Enter source pubkey: ")
|
||||
r, n, err := bytes.NewReader(srcPubKeyBytes), new(int64), new(error)
|
||||
srcPubKey := binary.ReadBinary(struct{ account.PubKey }{}, r, n, err).(struct{ account.PubKey }).PubKey
|
||||
srcPubKey := binary.ReadBinary(struct{ acm.PubKey }{}, r, n, err).(struct{ acm.PubKey }).PubKey
|
||||
if *err != nil {
|
||||
Exit(Fmt("Invalid PubKey. Error: %v", err))
|
||||
}
|
||||
|
||||
// Get the state of the account.
|
||||
var srcAccount *account.Account
|
||||
var srcAccount *acm.Account
|
||||
var srcAccountAddress = srcPubKey.Address()
|
||||
var srcAccountBalanceStr = "unknown"
|
||||
var srcAccountSequenceStr = "unknown"
|
||||
@ -90,7 +90,7 @@ func gen_tx() {
|
||||
Address: srcAddress,
|
||||
Amount: srcSendAmount,
|
||||
Sequence: srcSendSequence,
|
||||
Signature: account.SignatureEd25519{},
|
||||
Signature: acm.SignatureEd25519{},
|
||||
PubKey: srcPubKey,
|
||||
},
|
||||
},
|
||||
@ -108,12 +108,12 @@ func gen_tx() {
|
||||
// Get source privkey (for signing)
|
||||
srcPrivKeyBytes := getByteSliceFromHex("Enter source privkey (for signing): ")
|
||||
r, n, err = bytes.NewReader(srcPrivKeyBytes), new(int64), new(error)
|
||||
srcPrivKey := binary.ReadBinary(struct{ account.PrivKey }{}, r, n, err).(struct{ account.PrivKey }).PrivKey
|
||||
srcPrivKey := binary.ReadBinary(struct{ acm.PrivKey }{}, r, n, err).(struct{ acm.PrivKey }).PrivKey
|
||||
if *err != nil {
|
||||
Exit(Fmt("Invalid PrivKey. Error: %v", err))
|
||||
}
|
||||
|
||||
// Sign
|
||||
tx.Inputs[0].Signature = srcPrivKey.Sign(account.SignBytes(config.GetString("chain_id"), tx))
|
||||
tx.Inputs[0].Signature = srcPrivKey.Sign(acm.SignBytes(config.GetString("chain_id"), tx))
|
||||
fmt.Printf("Signed tx: %X\n", binary.BinaryBytes(tx))
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
bc "github.com/tendermint/tendermint/blockchain"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
@ -1011,7 +1011,7 @@ func (cs *ConsensusState) SetProposal(proposal *Proposal) error {
|
||||
}
|
||||
|
||||
// Verify signature
|
||||
if !cs.Validators.Proposer().PubKey.VerifyBytes(account.SignBytes(cs.state.ChainID, proposal), proposal.Signature) {
|
||||
if !cs.Validators.Proposer().PubKey.VerifyBytes(acm.SignBytes(cs.state.ChainID, proposal), proposal.Signature) {
|
||||
return ErrInvalidProposalSignature
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@ -17,11 +17,11 @@ var (
|
||||
)
|
||||
|
||||
type Proposal struct {
|
||||
Height int `json:"height"`
|
||||
Round int `json:"round"`
|
||||
BlockPartsHeader types.PartSetHeader `json:"block_parts_header"`
|
||||
POLRound int `json:"pol_round"` // -1 if null.
|
||||
Signature account.SignatureEd25519 `json:"signature"`
|
||||
Height int `json:"height"`
|
||||
Round int `json:"round"`
|
||||
BlockPartsHeader types.PartSetHeader `json:"block_parts_header"`
|
||||
POLRound int `json:"pol_round"` // -1 if null.
|
||||
Signature acm.SignatureEd25519 `json:"signature"`
|
||||
}
|
||||
|
||||
func NewProposal(height int, round int, blockPartsHeader types.PartSetHeader, polRound int) *Proposal {
|
||||
|
@ -3,7 +3,7 @@ package consensus
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
_ "github.com/tendermint/tendermint/config/tendermint_test"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@ -16,7 +16,7 @@ func TestProposalSignable(t *testing.T) {
|
||||
BlockPartsHeader: types.PartSetHeader{111, []byte("blockparts")},
|
||||
POLRound: -1,
|
||||
}
|
||||
signBytes := account.SignBytes(config.GetString("chain_id"), proposal)
|
||||
signBytes := acm.SignBytes(config.GetString("chain_id"), proposal)
|
||||
signStr := string(signBytes)
|
||||
|
||||
expected := Fmt(`{"chain_id":"%s","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_round":-1,"round":23456}}`,
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
@ -131,7 +131,7 @@ func (voteSet *VoteSet) addVote(val *sm.Validator, valIndex int, vote *types.Vot
|
||||
}
|
||||
|
||||
// Check signature.
|
||||
if !val.PubKey.VerifyBytes(account.SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
|
||||
if !val.PubKey.VerifyBytes(acm.SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
|
||||
// Bad signature.
|
||||
return false, 0, types.ErrVoteInvalidSignature
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/state"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"github.com/tendermint/tendermint/vm"
|
||||
)
|
||||
|
||||
func toVMAccount(acc *account.Account) *vm.Account {
|
||||
func toVMAccount(acc *acm.Account) *vm.Account {
|
||||
return &vm.Account{
|
||||
Address: LeftPadWord256(acc.Address),
|
||||
Balance: acc.Balance,
|
||||
@ -78,7 +78,7 @@ func CallCode(code, data []byte) (*ctypes.ResponseCall, error) {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) {
|
||||
func SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error) {
|
||||
// more checks?
|
||||
|
||||
for i, privAccount := range privAccounts {
|
||||
@ -101,17 +101,17 @@ func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error)
|
||||
bondTx := tx.(*types.BondTx)
|
||||
// the first privaccount corresponds to the BondTx pub key.
|
||||
// the rest to the inputs
|
||||
bondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), bondTx).(account.SignatureEd25519)
|
||||
bondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), bondTx).(acm.SignatureEd25519)
|
||||
for i, input := range bondTx.Inputs {
|
||||
input.PubKey = privAccounts[i+1].PubKey
|
||||
input.Signature = privAccounts[i+1].Sign(config.GetString("chain_id"), bondTx)
|
||||
}
|
||||
case *types.UnbondTx:
|
||||
unbondTx := tx.(*types.UnbondTx)
|
||||
unbondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), unbondTx).(account.SignatureEd25519)
|
||||
unbondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), unbondTx).(acm.SignatureEd25519)
|
||||
case *types.RebondTx:
|
||||
rebondTx := tx.(*types.RebondTx)
|
||||
rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(account.SignatureEd25519)
|
||||
rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(acm.SignatureEd25519)
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package core_types
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@ -18,8 +18,8 @@ type ResponseCall struct {
|
||||
}
|
||||
|
||||
type ResponseListAccounts struct {
|
||||
BlockHeight int `json:"block_height"`
|
||||
Accounts []*account.Account `json:"accounts"`
|
||||
BlockHeight int `json:"block_height"`
|
||||
Accounts []*acm.Account `json:"accounts"`
|
||||
}
|
||||
|
||||
type StorageItem struct {
|
||||
@ -51,7 +51,7 @@ type Receipt struct {
|
||||
type ResponseStatus struct {
|
||||
NodeInfo *types.NodeInfo `json:"node_info"`
|
||||
GenesisHash []byte `json:"genesis_hash"`
|
||||
PubKey account.PubKey `json:"pub_key"`
|
||||
PubKey acm.PubKey `json:"pub_key"`
|
||||
LatestBlockHash []byte `json:"latest_block_hash"`
|
||||
LatestBlockHeight int `json:"latest_block_height"`
|
||||
LatestBlockTime int64 `json:"latest_block_time"` // nano
|
||||
|
@ -4,7 +4,6 @@ package core_client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
@ -33,7 +32,7 @@ type Client interface {
|
||||
ListUnconfirmedTxs() ([]types.Tx, error)
|
||||
ListValidators() (*ctypes.ResponseListValidators, error)
|
||||
NetInfo() (*ctypes.ResponseNetInfo, error)
|
||||
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error)
|
||||
SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error)
|
||||
Status() (*ctypes.ResponseStatus, error)
|
||||
}
|
||||
|
||||
@ -547,7 +546,7 @@ func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) {
|
||||
func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error) {
|
||||
values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1066,7 +1065,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) {
|
||||
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error) {
|
||||
request := rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["SignTx"],
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
nm "github.com/tendermint/tendermint/node"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
@ -37,11 +37,11 @@ var (
|
||||
)
|
||||
|
||||
// deterministic account generation, synced with genesis file in config/tendermint_test/config.go
|
||||
func makeUsers(n int) []*account.PrivAccount {
|
||||
accounts := []*account.PrivAccount{}
|
||||
func makeUsers(n int) []*acm.PrivAccount {
|
||||
accounts := []*acm.PrivAccount{}
|
||||
for i := 0; i < n; i++ {
|
||||
secret := []byte("mysecret" + strconv.Itoa(i))
|
||||
user := account.GenPrivAccountFromSecret(secret)
|
||||
user := acm.GenPrivAccountFromSecret(secret)
|
||||
accounts = append(accounts, user)
|
||||
}
|
||||
return accounts
|
||||
@ -71,8 +71,8 @@ func init() {
|
||||
// Save new priv_validator file.
|
||||
priv := &state.PrivValidator{
|
||||
Address: user[0].Address,
|
||||
PubKey: account.PubKeyEd25519(user[0].PubKey.(account.PubKeyEd25519)),
|
||||
PrivKey: account.PrivKeyEd25519(user[0].PrivKey.(account.PrivKeyEd25519)),
|
||||
PubKey: acm.PubKeyEd25519(user[0].PubKey.(acm.PubKeyEd25519)),
|
||||
PrivKey: acm.PrivKeyEd25519(user[0].PrivKey.(acm.PrivKeyEd25519)),
|
||||
}
|
||||
priv.SetFile(config.GetString("priv_validator_file"))
|
||||
priv.Save()
|
||||
@ -133,7 +133,7 @@ func getNonce(t *testing.T, typ string, addr []byte) int {
|
||||
}
|
||||
|
||||
// get the account
|
||||
func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
|
||||
func getAccount(t *testing.T, typ string, addr []byte) *acm.Account {
|
||||
client := clients[typ]
|
||||
ac, err := client.GetAccount(addr)
|
||||
if err != nil {
|
||||
@ -143,9 +143,9 @@ func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
|
||||
}
|
||||
|
||||
// sign transaction
|
||||
func signTx(t *testing.T, typ string, tx types.Tx, privAcc *account.PrivAccount) types.Tx {
|
||||
func signTx(t *testing.T, typ string, tx types.Tx, privAcc *acm.PrivAccount) types.Tx {
|
||||
client := clients[typ]
|
||||
signedTx, err := client.SignTx(tx, []*account.PrivAccount{privAcc})
|
||||
signedTx, err := client.SignTx(tx, []*acm.PrivAccount{privAcc})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -219,12 +219,12 @@ func getNameRegEntry(t *testing.T, typ string, name string) *types.NameRegEntry
|
||||
//--------------------------------------------------------------------------------
|
||||
// utility verification function
|
||||
|
||||
func checkTx(t *testing.T, fromAddr []byte, priv *account.PrivAccount, tx *types.SendTx) {
|
||||
func checkTx(t *testing.T, fromAddr []byte, priv *acm.PrivAccount, tx *types.SendTx) {
|
||||
if bytes.Compare(tx.Inputs[0].Address, fromAddr) != 0 {
|
||||
t.Fatal("Tx input addresses don't match!")
|
||||
}
|
||||
|
||||
signBytes := account.SignBytes(chainID, tx)
|
||||
signBytes := acm.SignBytes(chainID, tx)
|
||||
in := tx.Inputs[0] //(*types.SendTx).Inputs[0]
|
||||
|
||||
if err := in.ValidateBasic(); err != nil {
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"sort"
|
||||
|
||||
ac "github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
dbm "github.com/tendermint/tendermint/db"
|
||||
@ -48,7 +48,7 @@ func (cache *BlockCache) State() *State {
|
||||
//-------------------------------------
|
||||
// BlockCache.account
|
||||
|
||||
func (cache *BlockCache) GetAccount(addr []byte) *ac.Account {
|
||||
func (cache *BlockCache) GetAccount(addr []byte) *acm.Account {
|
||||
acc, _, removed, _ := cache.accounts[string(addr)].unpack()
|
||||
if removed {
|
||||
return nil
|
||||
@ -61,7 +61,7 @@ func (cache *BlockCache) GetAccount(addr []byte) *ac.Account {
|
||||
}
|
||||
}
|
||||
|
||||
func (cache *BlockCache) UpdateAccount(acc *ac.Account) {
|
||||
func (cache *BlockCache) UpdateAccount(acc *acm.Account) {
|
||||
addr := acc.Address
|
||||
_, storage, removed, _ := cache.accounts[string(addr)].unpack()
|
||||
// SANITY CHECK
|
||||
@ -178,7 +178,7 @@ func (cache *BlockCache) Sync() {
|
||||
// Later we'll iterate over all the users and save storage + update storage root.
|
||||
var (
|
||||
curAddr Word256
|
||||
curAcc *ac.Account
|
||||
curAcc *acm.Account
|
||||
curAccRemoved bool
|
||||
curStorage merkle.Tree
|
||||
)
|
||||
@ -274,13 +274,13 @@ func (cache *BlockCache) Sync() {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type accountInfo struct {
|
||||
account *ac.Account
|
||||
account *acm.Account
|
||||
storage merkle.Tree
|
||||
removed bool
|
||||
dirty bool
|
||||
}
|
||||
|
||||
func (accInfo accountInfo) unpack() (*ac.Account, merkle.Tree, bool, bool) {
|
||||
func (accInfo accountInfo) unpack() (*acm.Account, merkle.Tree, bool, bool) {
|
||||
return accInfo.account, accInfo.storage, accInfo.removed, accInfo.dirty
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
ac "github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/vm"
|
||||
)
|
||||
|
||||
type AccountGetter interface {
|
||||
GetAccount(addr []byte) *ac.Account
|
||||
GetAccount(addr []byte) *acm.Account
|
||||
}
|
||||
|
||||
type VMAccountState interface {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/events"
|
||||
ptypes "github.com/tendermint/tendermint/permission/types" // for GlobalPermissionAddress ...
|
||||
@ -138,11 +138,11 @@ func execBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeade
|
||||
}
|
||||
|
||||
// The accounts from the TxInputs must either already have
|
||||
// account.PubKey.(type) != nil, (it must be known),
|
||||
// acm.PubKey.(type) != nil, (it must be known),
|
||||
// or it must be specified in the TxInput. If redeclared,
|
||||
// the TxInput is modified and input.PubKey set to nil.
|
||||
func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*account.Account, error) {
|
||||
accounts := map[string]*account.Account{}
|
||||
func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*acm.Account, error) {
|
||||
accounts := map[string]*acm.Account{}
|
||||
for _, in := range ins {
|
||||
// Account shouldn't be duplicated
|
||||
if _, ok := accounts[string(in.Address)]; ok {
|
||||
@ -161,9 +161,9 @@ func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*account.A
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account, outs []*types.TxOutput) (map[string]*account.Account, error) {
|
||||
func getOrMakeOutputs(state AccountGetter, accounts map[string]*acm.Account, outs []*types.TxOutput) (map[string]*acm.Account, error) {
|
||||
if accounts == nil {
|
||||
accounts = make(map[string]*account.Account)
|
||||
accounts = make(map[string]*acm.Account)
|
||||
}
|
||||
|
||||
// we should err if an account is being created but the inputs don't have permission
|
||||
@ -182,7 +182,7 @@ func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account,
|
||||
}
|
||||
checkedCreatePerms = true
|
||||
}
|
||||
acc = &account.Account{
|
||||
acc = &acm.Account{
|
||||
Address: out.Address,
|
||||
PubKey: nil,
|
||||
Sequence: 0,
|
||||
@ -195,7 +195,7 @@ func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account,
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func checkInputPubKey(acc *account.Account, in *types.TxInput) error {
|
||||
func checkInputPubKey(acc *acm.Account, in *types.TxInput) error {
|
||||
if acc.PubKey == nil {
|
||||
if in.PubKey == nil {
|
||||
return types.ErrTxUnknownPubKey
|
||||
@ -210,7 +210,7 @@ func checkInputPubKey(acc *account.Account, in *types.TxInput) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateInputs(accounts map[string]*account.Account, signBytes []byte, ins []*types.TxInput) (total int64, err error) {
|
||||
func validateInputs(accounts map[string]*acm.Account, signBytes []byte, ins []*types.TxInput) (total int64, err error) {
|
||||
for _, in := range ins {
|
||||
acc := accounts[string(in.Address)]
|
||||
// SANITY CHECK
|
||||
@ -228,7 +228,7 @@ func validateInputs(accounts map[string]*account.Account, signBytes []byte, ins
|
||||
return total, nil
|
||||
}
|
||||
|
||||
func validateInput(acc *account.Account, signBytes []byte, in *types.TxInput) (err error) {
|
||||
func validateInput(acc *acm.Account, signBytes []byte, in *types.TxInput) (err error) {
|
||||
// Check TxInput basic
|
||||
if err := in.ValidateBasic(); err != nil {
|
||||
return err
|
||||
@ -263,7 +263,7 @@ func validateOutputs(outs []*types.TxOutput) (total int64, err error) {
|
||||
return total, nil
|
||||
}
|
||||
|
||||
func adjustByInputs(accounts map[string]*account.Account, ins []*types.TxInput) {
|
||||
func adjustByInputs(accounts map[string]*acm.Account, ins []*types.TxInput) {
|
||||
for _, in := range ins {
|
||||
acc := accounts[string(in.Address)]
|
||||
// SANITY CHECK
|
||||
@ -279,7 +279,7 @@ func adjustByInputs(accounts map[string]*account.Account, ins []*types.TxInput)
|
||||
}
|
||||
}
|
||||
|
||||
func adjustByOutputs(accounts map[string]*account.Account, outs []*types.TxOutput) {
|
||||
func adjustByOutputs(accounts map[string]*acm.Account, outs []*types.TxOutput) {
|
||||
for _, out := range outs {
|
||||
acc := accounts[string(out.Address)]
|
||||
// SANITY CHECK
|
||||
@ -319,7 +319,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
return err
|
||||
}
|
||||
|
||||
signBytes := account.SignBytes(_s.ChainID, tx)
|
||||
signBytes := acm.SignBytes(_s.ChainID, tx)
|
||||
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -354,7 +354,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
return nil
|
||||
|
||||
case *types.CallTx:
|
||||
var inAcc, outAcc *account.Account
|
||||
var inAcc, outAcc *acm.Account
|
||||
|
||||
// Validate input
|
||||
inAcc = blockCache.GetAccount(tx.Input.Address)
|
||||
@ -379,7 +379,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address))
|
||||
return err
|
||||
}
|
||||
signBytes := account.SignBytes(_s.ChainID, tx)
|
||||
signBytes := acm.SignBytes(_s.ChainID, tx)
|
||||
err := validateInput(inAcc, signBytes, tx.Input)
|
||||
if err != nil {
|
||||
log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err))
|
||||
@ -433,7 +433,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
// check if its an snative
|
||||
if _, ok := vm.RegisteredSNativeContracts[LeftPadWord256(tx.Address)]; ok {
|
||||
// set the outAcc (simply a placeholder until we reach the call)
|
||||
outAcc = &account.Account{Address: tx.Address}
|
||||
outAcc = &acm.Account{Address: tx.Address}
|
||||
} else {
|
||||
// if you call an account that doesn't exist
|
||||
// or an account with no code then we take fees (sorry pal)
|
||||
@ -511,7 +511,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
return nil
|
||||
|
||||
case *types.NameTx:
|
||||
var inAcc *account.Account
|
||||
var inAcc *acm.Account
|
||||
|
||||
// Validate input
|
||||
inAcc = blockCache.GetAccount(tx.Input.Address)
|
||||
@ -528,7 +528,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address))
|
||||
return err
|
||||
}
|
||||
signBytes := account.SignBytes(_s.ChainID, tx)
|
||||
signBytes := acm.SignBytes(_s.ChainID, tx)
|
||||
err := validateInput(inAcc, signBytes, tx.Input)
|
||||
if err != nil {
|
||||
log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err))
|
||||
@ -661,14 +661,11 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
return fmt.Errorf("At least one input lacks permission to bond")
|
||||
}
|
||||
|
||||
signBytes := account.SignBytes(_s.ChainID, tx)
|
||||
signBytes := acm.SignBytes(_s.ChainID, tx)
|
||||
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.PubKey.ValidateBasic(); err != nil {
|
||||
return err
|
||||
}
|
||||
if !tx.PubKey.VerifyBytes(signBytes, tx.Signature) {
|
||||
return types.ErrTxInvalidSignature
|
||||
}
|
||||
@ -720,7 +717,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
}
|
||||
|
||||
// Verify the signature
|
||||
signBytes := account.SignBytes(_s.ChainID, tx)
|
||||
signBytes := acm.SignBytes(_s.ChainID, tx)
|
||||
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
|
||||
return types.ErrTxInvalidSignature
|
||||
}
|
||||
@ -745,7 +742,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
}
|
||||
|
||||
// Verify the signature
|
||||
signBytes := account.SignBytes(_s.ChainID, tx)
|
||||
signBytes := acm.SignBytes(_s.ChainID, tx)
|
||||
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
|
||||
return types.ErrTxInvalidSignature
|
||||
}
|
||||
@ -774,8 +771,8 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
return types.ErrTxInvalidAddress
|
||||
}
|
||||
}
|
||||
voteASignBytes := account.SignBytes(_s.ChainID, &tx.VoteA)
|
||||
voteBSignBytes := account.SignBytes(_s.ChainID, &tx.VoteB)
|
||||
voteASignBytes := acm.SignBytes(_s.ChainID, &tx.VoteA)
|
||||
voteBSignBytes := acm.SignBytes(_s.ChainID, &tx.VoteB)
|
||||
if !accused.PubKey.VerifyBytes(voteASignBytes, tx.VoteA.Signature) ||
|
||||
!accused.PubKey.VerifyBytes(voteBSignBytes, tx.VoteB.Signature) {
|
||||
return types.ErrTxInvalidSignature
|
||||
@ -814,7 +811,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||
//---------------------------------------------------------------
|
||||
|
||||
// Get permission on an account or fall back to global value
|
||||
func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFlag) bool {
|
||||
func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag) bool {
|
||||
if perm > ptypes.AllBasePermFlags {
|
||||
panic("Checking an unknown permission in state should never happen")
|
||||
}
|
||||
@ -840,7 +837,7 @@ func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFl
|
||||
}
|
||||
|
||||
// TODO: for debug log the failed accounts
|
||||
func hasSendPermission(state AccountGetter, accs map[string]*account.Account) bool {
|
||||
func hasSendPermission(state AccountGetter, accs map[string]*acm.Account) bool {
|
||||
for _, acc := range accs {
|
||||
if !HasPermission(state, acc, ptypes.Send) {
|
||||
return false
|
||||
@ -849,19 +846,19 @@ func hasSendPermission(state AccountGetter, accs map[string]*account.Account) bo
|
||||
return true
|
||||
}
|
||||
|
||||
func hasNamePermission(state AccountGetter, acc *account.Account) bool {
|
||||
func hasNamePermission(state AccountGetter, acc *acm.Account) bool {
|
||||
return HasPermission(state, acc, ptypes.Name)
|
||||
}
|
||||
|
||||
func hasCallPermission(state AccountGetter, acc *account.Account) bool {
|
||||
func hasCallPermission(state AccountGetter, acc *acm.Account) bool {
|
||||
return HasPermission(state, acc, ptypes.Call)
|
||||
}
|
||||
|
||||
func hasCreateContractPermission(state AccountGetter, acc *account.Account) bool {
|
||||
func hasCreateContractPermission(state AccountGetter, acc *acm.Account) bool {
|
||||
return HasPermission(state, acc, ptypes.CreateContract)
|
||||
}
|
||||
|
||||
func hasCreateAccountPermission(state AccountGetter, accs map[string]*account.Account) bool {
|
||||
func hasCreateAccountPermission(state AccountGetter, accs map[string]*acm.Account) bool {
|
||||
for _, acc := range accs {
|
||||
if !HasPermission(state, acc, ptypes.CreateAccount) {
|
||||
return false
|
||||
@ -870,11 +867,11 @@ func hasCreateAccountPermission(state AccountGetter, accs map[string]*account.Ac
|
||||
return true
|
||||
}
|
||||
|
||||
func hasBondPermission(state AccountGetter, acc *account.Account) bool {
|
||||
func hasBondPermission(state AccountGetter, acc *acm.Account) bool {
|
||||
return HasPermission(state, acc, ptypes.Bond)
|
||||
}
|
||||
|
||||
func hasBondOrSendPermission(state AccountGetter, accs map[string]*account.Account) bool {
|
||||
func hasBondOrSendPermission(state AccountGetter, accs map[string]*acm.Account) bool {
|
||||
for _, acc := range accs {
|
||||
if !HasPermission(state, acc, ptypes.Bond) {
|
||||
if !HasPermission(state, acc, ptypes.Send) {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
dbm "github.com/tendermint/tendermint/db"
|
||||
@ -35,10 +35,10 @@ type GenesisAccount struct {
|
||||
}
|
||||
|
||||
type GenesisValidator struct {
|
||||
PubKey account.PubKeyEd25519 `json:"pub_key"`
|
||||
Amount int64 `json:"amount"`
|
||||
Name string `json:"name"`
|
||||
UnbondTo []BasicAccount `json:"unbond_to"`
|
||||
PubKey acm.PubKeyEd25519 `json:"pub_key"`
|
||||
Amount int64 `json:"amount"`
|
||||
Name string `json:"name"`
|
||||
UnbondTo []BasicAccount `json:"unbond_to"`
|
||||
}
|
||||
|
||||
type GenesisParams struct {
|
||||
@ -86,13 +86,13 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
|
||||
}
|
||||
|
||||
// Make accounts state tree
|
||||
accounts := merkle.NewIAVLTree(binary.BasicCodec, account.AccountCodec, defaultAccountsCacheCapacity, db)
|
||||
accounts := merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
|
||||
for _, genAcc := range genDoc.Accounts {
|
||||
perm := ptypes.ZeroAccountPermissions
|
||||
if genAcc.Permissions != nil {
|
||||
perm = *genAcc.Permissions
|
||||
}
|
||||
acc := &account.Account{
|
||||
acc := &acm.Account{
|
||||
Address: genAcc.Address,
|
||||
PubKey: nil,
|
||||
Sequence: 0,
|
||||
@ -112,7 +112,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
|
||||
globalPerms.Base.SetBit = ptypes.AllPermFlags
|
||||
}
|
||||
|
||||
permsAcc := &account.Account{
|
||||
permsAcc := &acm.Account{
|
||||
Address: ptypes.GlobalPermissionsAddress,
|
||||
PubKey: nil,
|
||||
Sequence: 0,
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
dbm "github.com/tendermint/tendermint/db"
|
||||
"github.com/tendermint/tendermint/events"
|
||||
@ -81,11 +81,11 @@ x - roles: has, add, rm
|
||||
var user = makeUsers(10)
|
||||
var chainID = "testchain"
|
||||
|
||||
func makeUsers(n int) []*account.PrivAccount {
|
||||
accounts := []*account.PrivAccount{}
|
||||
func makeUsers(n int) []*acm.PrivAccount {
|
||||
accounts := []*acm.PrivAccount{}
|
||||
for i := 0; i < n; i++ {
|
||||
secret := []byte("mysecret" + strconv.Itoa(i))
|
||||
user := account.GenPrivAccountFromSecret(secret)
|
||||
user := acm.GenPrivAccountFromSecret(secret)
|
||||
accounts = append(accounts, user)
|
||||
}
|
||||
return accounts
|
||||
@ -115,7 +115,7 @@ func newBaseGenDoc(globalPerm, accountPerm ptypes.AccountPermissions) GenesisDoc
|
||||
Accounts: genAccounts,
|
||||
Validators: []GenesisValidator{
|
||||
GenesisValidator{
|
||||
PubKey: user[0].PubKey.(account.PubKeyEd25519),
|
||||
PubKey: user[0].PubKey.(acm.PubKeyEd25519),
|
||||
Amount: 10,
|
||||
UnbondTo: []BasicAccount{
|
||||
BasicAccount{
|
||||
@ -348,7 +348,7 @@ func TestCallPermission(t *testing.T) {
|
||||
|
||||
// create simple contract
|
||||
simpleContractAddr := NewContractAddress(user[0].Address, 100)
|
||||
simpleAcc := &account.Account{
|
||||
simpleAcc := &acm.Account{
|
||||
Address: simpleContractAddr,
|
||||
Balance: 0,
|
||||
Code: []byte{0x60},
|
||||
@ -372,7 +372,7 @@ func TestCallPermission(t *testing.T) {
|
||||
// create contract that calls the simple contract
|
||||
contractCode := callContractCode(simpleContractAddr)
|
||||
caller1ContractAddr := NewContractAddress(user[0].Address, 101)
|
||||
caller1Acc := &account.Account{
|
||||
caller1Acc := &acm.Account{
|
||||
Address: caller1ContractAddr,
|
||||
Balance: 0,
|
||||
Code: contractCode,
|
||||
@ -416,7 +416,7 @@ func TestCallPermission(t *testing.T) {
|
||||
|
||||
contractCode2 := callContractCode(caller1ContractAddr)
|
||||
caller2ContractAddr := NewContractAddress(user[0].Address, 102)
|
||||
caller2Acc := &account.Account{
|
||||
caller2Acc := &acm.Account{
|
||||
Address: caller2ContractAddr,
|
||||
Balance: 1000,
|
||||
Code: contractCode2,
|
||||
@ -548,7 +548,7 @@ func TestCreatePermission(t *testing.T) {
|
||||
code := callContractCode(zeroAddr)
|
||||
|
||||
contractAddr = NewContractAddress(user[0].Address, 110)
|
||||
contractAcc = &account.Account{
|
||||
contractAcc = &acm.Account{
|
||||
Address: contractAddr,
|
||||
Balance: 1000,
|
||||
Code: code,
|
||||
@ -579,7 +579,7 @@ func TestBondPermission(t *testing.T) {
|
||||
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
|
||||
st := MakeGenesisState(stateDB, &genDoc)
|
||||
blockCache := NewBlockCache(st)
|
||||
var bondAcc *account.Account
|
||||
var bondAcc *acm.Account
|
||||
|
||||
//------------------------------
|
||||
// one bonder without permission should fail
|
||||
@ -800,7 +800,7 @@ func TestCreateAccountPermission(t *testing.T) {
|
||||
// create contract that calls the simple contract
|
||||
contractCode := callContractCode(user[9].Address)
|
||||
caller1ContractAddr := NewContractAddress(user[4].Address, 101)
|
||||
caller1Acc := &account.Account{
|
||||
caller1Acc := &acm.Account{
|
||||
Address: caller1ContractAddr,
|
||||
Balance: 0,
|
||||
Code: contractCode,
|
||||
@ -851,7 +851,7 @@ func TestSNativeCALL(t *testing.T) {
|
||||
// Test CALL to SNative contracts
|
||||
|
||||
// make the main contract once
|
||||
doug := &account.Account{
|
||||
doug := &acm.Account{
|
||||
Address: ptypes.DougAddress,
|
||||
Balance: 0,
|
||||
Code: nil,
|
||||
@ -985,7 +985,7 @@ func TestSNativeCallTx(t *testing.T) {
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test CallTx to SNative contracts
|
||||
var doug *account.Account = nil
|
||||
var doug *acm.Account = nil
|
||||
|
||||
fmt.Println("#### hasBasePerm")
|
||||
// hasBasePerm
|
||||
@ -1131,7 +1131,7 @@ func execTxWaitEvent(t *testing.T, blockCache *BlockCache, tx types.Tx, eventid
|
||||
}
|
||||
|
||||
// give a contract perms for an snative, call it, it calls the snative, ensure the check funciton (f) succeeds
|
||||
func testSNativeCALLExpectPass(t *testing.T, blockCache *BlockCache, doug *account.Account, snativeAddress, data []byte, f func([]byte) error) {
|
||||
func testSNativeCALLExpectPass(t *testing.T, blockCache *BlockCache, doug *acm.Account, snativeAddress, data []byte, f func([]byte) error) {
|
||||
perm := vm.RegisteredSNativePermissions[LeftPadWord256(snativeAddress)]
|
||||
var addr []byte
|
||||
if doug != nil {
|
||||
@ -1160,7 +1160,7 @@ func testSNativeCALLExpectPass(t *testing.T, blockCache *BlockCache, doug *accou
|
||||
}
|
||||
|
||||
// assumes the contract has not been given the permission. calls the it, it calls the snative, expects to fail
|
||||
func testSNativeCALLExpectFail(t *testing.T, blockCache *BlockCache, doug *account.Account, snativeAddress, data []byte) {
|
||||
func testSNativeCALLExpectFail(t *testing.T, blockCache *BlockCache, doug *acm.Account, snativeAddress, data []byte) {
|
||||
var addr []byte
|
||||
if doug != nil {
|
||||
contractCode := callContractCode(snativeAddress)
|
||||
@ -1189,7 +1189,7 @@ func boolToWord256(v bool) Word256 {
|
||||
return LeftPadWord256([]byte{vint})
|
||||
}
|
||||
|
||||
func snativePermTestInput(name string, user *account.PrivAccount, perm ptypes.PermFlag, val bool) (addr []byte, data []byte) {
|
||||
func snativePermTestInput(name string, user *acm.PrivAccount, perm ptypes.PermFlag, val bool) (addr []byte, data []byte) {
|
||||
addr = LeftPadWord256([]byte(name)).Postfix(20)
|
||||
switch name {
|
||||
case "hasBasePerm", "unsetBasePerm":
|
||||
@ -1207,7 +1207,7 @@ func snativePermTestInput(name string, user *account.PrivAccount, perm ptypes.Pe
|
||||
return
|
||||
}
|
||||
|
||||
func snativeRoleTestInput(name string, user *account.PrivAccount, role string) (addr []byte, data []byte) {
|
||||
func snativeRoleTestInput(name string, user *acm.PrivAccount, role string) (addr []byte, data []byte) {
|
||||
addr = LeftPadWord256([]byte(name)).Postfix(20)
|
||||
data = LeftPadBytes(user.Address, 32)
|
||||
data = append(data, LeftPadBytes([]byte(role), 32)...)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"math"
|
||||
"sync"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
. "github.com/tendermint/tendermint/consensus/types"
|
||||
@ -37,12 +37,12 @@ func voteToStep(vote *types.Vote) int8 {
|
||||
}
|
||||
|
||||
type PrivValidator struct {
|
||||
Address []byte `json:"address"`
|
||||
PubKey account.PubKeyEd25519 `json:"pub_key"`
|
||||
PrivKey account.PrivKeyEd25519 `json:"priv_key"`
|
||||
LastHeight int `json:"last_height"`
|
||||
LastRound int `json:"last_round"`
|
||||
LastStep int8 `json:"last_step"`
|
||||
Address []byte `json:"address"`
|
||||
PubKey acm.PubKeyEd25519 `json:"pub_key"`
|
||||
PrivKey acm.PrivKeyEd25519 `json:"priv_key"`
|
||||
LastHeight int `json:"last_height"`
|
||||
LastRound int `json:"last_round"`
|
||||
LastStep int8 `json:"last_step"`
|
||||
|
||||
// For persistence.
|
||||
// Overloaded for testing.
|
||||
@ -55,8 +55,8 @@ func GenPrivValidator() *PrivValidator {
|
||||
privKeyBytes := new([64]byte)
|
||||
copy(privKeyBytes[:32], CRandBytes(32))
|
||||
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
|
||||
pubKey := account.PubKeyEd25519(*pubKeyBytes)
|
||||
privKey := account.PrivKeyEd25519(*privKeyBytes)
|
||||
pubKey := acm.PubKeyEd25519(*pubKeyBytes)
|
||||
privKey := acm.PrivKeyEd25519(*privKeyBytes)
|
||||
return &PrivValidator{
|
||||
Address: pubKey.Address(),
|
||||
PubKey: pubKey,
|
||||
@ -138,7 +138,7 @@ func (privVal *PrivValidator) SignVote(chainID string, vote *types.Vote) error {
|
||||
}
|
||||
|
||||
func (privVal *PrivValidator) SignVoteUnsafe(chainID string, vote *types.Vote) {
|
||||
vote.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, vote)).(account.SignatureEd25519)
|
||||
vote.Signature = privVal.PrivKey.Sign(acm.SignBytes(chainID, vote)).(acm.SignatureEd25519)
|
||||
}
|
||||
|
||||
func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error {
|
||||
@ -155,7 +155,7 @@ func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) e
|
||||
privVal.save()
|
||||
|
||||
// Sign
|
||||
proposal.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, proposal)).(account.SignatureEd25519)
|
||||
proposal.Signature = privVal.PrivKey.Sign(acm.SignBytes(chainID, proposal)).(acm.SignatureEd25519)
|
||||
return nil
|
||||
} else {
|
||||
return errors.New(fmt.Sprintf("Attempt of duplicate signing of proposal: Height %v, Round %v", proposal.Height, proposal.Round))
|
||||
@ -175,7 +175,7 @@ func (privVal *PrivValidator) SignRebondTx(chainID string, rebondTx *types.Rebon
|
||||
privVal.save()
|
||||
|
||||
// Sign
|
||||
rebondTx.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, rebondTx)).(account.SignatureEd25519)
|
||||
rebondTx.Signature = privVal.PrivKey.Sign(acm.SignBytes(chainID, rebondTx)).(acm.SignatureEd25519)
|
||||
return nil
|
||||
} else {
|
||||
return errors.New(fmt.Sprintf("Attempt of duplicate signing of rebondTx: Height %v", rebondTx.Height))
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
dbm "github.com/tendermint/tendermint/db"
|
||||
@ -58,7 +58,7 @@ func LoadState(db dbm.DB) *State {
|
||||
s.LastBondedValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
||||
s.UnbondingValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
||||
accountsHash := binary.ReadByteSlice(r, n, err)
|
||||
s.accounts = merkle.NewIAVLTree(binary.BasicCodec, account.AccountCodec, defaultAccountsCacheCapacity, db)
|
||||
s.accounts = merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
|
||||
s.accounts.Load(accountsHash)
|
||||
validatorInfosHash := binary.ReadByteSlice(r, n, err)
|
||||
s.validatorInfos = merkle.NewIAVLTree(binary.BasicCodec, ValidatorInfoCodec, 0, db)
|
||||
@ -155,18 +155,18 @@ func (s *State) SetDB(db dbm.DB) {
|
||||
// The returned Account is a copy, so mutating it
|
||||
// has no side effects.
|
||||
// Implements Statelike
|
||||
func (s *State) GetAccount(address []byte) *account.Account {
|
||||
func (s *State) GetAccount(address []byte) *acm.Account {
|
||||
_, acc := s.accounts.Get(address)
|
||||
if acc == nil {
|
||||
return nil
|
||||
}
|
||||
return acc.(*account.Account).Copy()
|
||||
return acc.(*acm.Account).Copy()
|
||||
}
|
||||
|
||||
// The account is copied before setting, so mutating it
|
||||
// afterwards has no side effects.
|
||||
// Implements Statelike
|
||||
func (s *State) UpdateAccount(account *account.Account) bool {
|
||||
func (s *State) UpdateAccount(account *acm.Account) bool {
|
||||
return s.accounts.Set(account.Address, account.Copy())
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"sort"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
dbm "github.com/tendermint/tendermint/db"
|
||||
ptypes "github.com/tendermint/tendermint/permission/types"
|
||||
@ -23,10 +23,10 @@ func Tempfile(prefix string) (*os.File, string) {
|
||||
return file, file.Name()
|
||||
}
|
||||
|
||||
func RandAccount(randBalance bool, minBalance int64) (*account.Account, *account.PrivAccount) {
|
||||
privAccount := account.GenPrivAccount()
|
||||
func RandAccount(randBalance bool, minBalance int64) (*acm.Account, *acm.PrivAccount) {
|
||||
privAccount := acm.GenPrivAccount()
|
||||
perms := ptypes.DefaultAccountPermissions
|
||||
acc := &account.Account{
|
||||
acc := &acm.Account{
|
||||
Address: privAccount.PubKey.Address(),
|
||||
PubKey: privAccount.PubKey,
|
||||
Sequence: RandInt(),
|
||||
@ -69,9 +69,9 @@ func RandValidator(randBonded bool, minBonded int64) (*ValidatorInfo, *Validator
|
||||
return valInfo, val, privVal
|
||||
}
|
||||
|
||||
func RandGenesisDoc(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*GenesisDoc, []*account.PrivAccount, []*PrivValidator) {
|
||||
func RandGenesisDoc(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*GenesisDoc, []*acm.PrivAccount, []*PrivValidator) {
|
||||
accounts := make([]GenesisAccount, numAccounts)
|
||||
privAccounts := make([]*account.PrivAccount, numAccounts)
|
||||
privAccounts := make([]*acm.PrivAccount, numAccounts)
|
||||
defaultPerms := ptypes.DefaultAccountPermissions
|
||||
for i := 0; i < numAccounts; i++ {
|
||||
account, privAccount := RandAccount(randBalance, minBalance)
|
||||
@ -108,7 +108,7 @@ func RandGenesisDoc(numAccounts int, randBalance bool, minBalance int64, numVali
|
||||
|
||||
}
|
||||
|
||||
func RandGenesisState(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*State, []*account.PrivAccount, []*PrivValidator) {
|
||||
func RandGenesisState(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*State, []*acm.PrivAccount, []*PrivValidator) {
|
||||
db := dbm.NewMemDB()
|
||||
genDoc, privAccounts, privValidators := RandGenesisDoc(numAccounts, randBalance, minBalance, numValidators, randBonded, minBonded)
|
||||
s0 := MakeGenesisState(db, genDoc)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
ac "github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
ptypes "github.com/tendermint/tendermint/permission/types" // for GlobalPermissionAddress ...
|
||||
"github.com/tendermint/tendermint/vm"
|
||||
@ -158,7 +158,7 @@ func NewContractAddress(caller []byte, nonce int) []byte {
|
||||
}
|
||||
|
||||
// Converts backend.Account to vm.Account struct.
|
||||
func toVMAccount(acc *ac.Account) *vm.Account {
|
||||
func toVMAccount(acc *acm.Account) *vm.Account {
|
||||
return &vm.Account{
|
||||
Address: LeftPadWord256(acc.Address),
|
||||
Balance: acc.Balance,
|
||||
@ -171,8 +171,8 @@ func toVMAccount(acc *ac.Account) *vm.Account {
|
||||
}
|
||||
|
||||
// Converts vm.Account to backend.Account struct.
|
||||
func toStateAccount(acc *vm.Account) *ac.Account {
|
||||
pubKey, ok := acc.Other.(ac.PubKey)
|
||||
func toStateAccount(acc *vm.Account) *acm.Account {
|
||||
pubKey, ok := acc.Other.(acm.PubKey)
|
||||
if !ok {
|
||||
pubKey = nil
|
||||
}
|
||||
@ -183,7 +183,7 @@ func toStateAccount(acc *vm.Account) *ac.Account {
|
||||
} else {
|
||||
storageRoot = acc.StorageRoot.Bytes()
|
||||
}
|
||||
return &ac.Account{
|
||||
return &acm.Account{
|
||||
Address: acc.Address.Postfix(20),
|
||||
PubKey: pubKey,
|
||||
Balance: acc.Balance,
|
||||
|
@ -5,21 +5,21 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// Persistent (mostly) static data for each Validator
|
||||
type ValidatorInfo struct {
|
||||
Address []byte `json:"address"`
|
||||
PubKey account.PubKeyEd25519 `json:"pub_key"`
|
||||
UnbondTo []*types.TxOutput `json:"unbond_to"`
|
||||
FirstBondHeight int `json:"first_bond_height"`
|
||||
FirstBondAmount int64 `json:"first_bond_amount"`
|
||||
DestroyedHeight int `json:"destroyed_height"` // If destroyed
|
||||
DestroyedAmount int64 `json:"destroyed_amount"` // If destroyed
|
||||
ReleasedHeight int `json:"released_height"` // If released
|
||||
Address []byte `json:"address"`
|
||||
PubKey acm.PubKeyEd25519 `json:"pub_key"`
|
||||
UnbondTo []*types.TxOutput `json:"unbond_to"`
|
||||
FirstBondHeight int `json:"first_bond_height"`
|
||||
FirstBondAmount int64 `json:"first_bond_amount"`
|
||||
DestroyedHeight int `json:"destroyed_height"` // If destroyed
|
||||
DestroyedAmount int64 `json:"destroyed_amount"` // If destroyed
|
||||
ReleasedHeight int `json:"released_height"` // If released
|
||||
}
|
||||
|
||||
func (valInfo *ValidatorInfo) Copy() *ValidatorInfo {
|
||||
@ -46,13 +46,13 @@ var ValidatorInfoCodec = binary.Codec{
|
||||
// Also persisted with the state, but fields change
|
||||
// every height|round so they don't go in merkle.Tree
|
||||
type Validator struct {
|
||||
Address []byte `json:"address"`
|
||||
PubKey account.PubKeyEd25519 `json:"pub_key"`
|
||||
BondHeight int `json:"bond_height"`
|
||||
UnbondHeight int `json:"unbond_height"`
|
||||
LastCommitHeight int `json:"last_commit_height"`
|
||||
VotingPower int64 `json:"voting_power"`
|
||||
Accum int64 `json:"accum"`
|
||||
Address []byte `json:"address"`
|
||||
PubKey acm.PubKeyEd25519 `json:"pub_key"`
|
||||
BondHeight int `json:"bond_height"`
|
||||
UnbondHeight int `json:"unbond_height"`
|
||||
LastCommitHeight int `json:"last_commit_height"`
|
||||
VotingPower int64 `json:"voting_power"`
|
||||
Accum int64 `json:"accum"`
|
||||
}
|
||||
|
||||
// Creates a new copy of the validator so we can mutate accum.
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/merkle"
|
||||
@ -310,7 +310,7 @@ func (data *Data) Hash() []byte {
|
||||
if data.hash == nil {
|
||||
bs := make([]interface{}, len(data.Txs))
|
||||
for i, tx := range data.Txs {
|
||||
bs[i] = account.SignBytes(config.GetString("chain_id"), tx)
|
||||
bs[i] = acm.SignBytes(config.GetString("chain_id"), tx)
|
||||
}
|
||||
data.hash = merkle.SimpleHashFromBinaries(bs) // NOTE: leaves are TxIDs.
|
||||
}
|
||||
|
34
types/tx.go
34
types/tx.go
@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
)
|
||||
@ -78,11 +78,11 @@ var _ = binary.RegisterInterface(
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type TxInput struct {
|
||||
Address []byte `json:"address"` // Hash of the PubKey
|
||||
Amount int64 `json:"amount"` // Must not exceed account balance
|
||||
Sequence int `json:"sequence"` // Must be 1 greater than the last committed TxInput
|
||||
Signature account.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
|
||||
PubKey account.PubKey `json:"pub_key"` // Must not be nil, may be nil
|
||||
Address []byte `json:"address"` // Hash of the PubKey
|
||||
Amount int64 `json:"amount"` // Must not exceed account balance
|
||||
Sequence int `json:"sequence"` // Must be 1 greater than the last committed TxInput
|
||||
Signature acm.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
|
||||
PubKey acm.PubKey `json:"pub_key"` // Must not be nil, may be nil
|
||||
}
|
||||
|
||||
func (txIn *TxInput) ValidateBasic() error {
|
||||
@ -231,10 +231,10 @@ func (tx *NameTx) String() string {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type BondTx struct {
|
||||
PubKey account.PubKeyEd25519 `json:"pub_key"`
|
||||
Signature account.SignatureEd25519 `json:"signature"`
|
||||
Inputs []*TxInput `json:"inputs"`
|
||||
UnbondTo []*TxOutput `json:"unbond_to"`
|
||||
PubKey acm.PubKeyEd25519 `json:"pub_key"`
|
||||
Signature acm.SignatureEd25519 `json:"signature"`
|
||||
Inputs []*TxInput `json:"inputs"`
|
||||
UnbondTo []*TxOutput `json:"unbond_to"`
|
||||
}
|
||||
|
||||
func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||
@ -265,9 +265,9 @@ func (tx *BondTx) String() string {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type UnbondTx struct {
|
||||
Address []byte `json:"address"`
|
||||
Height int `json:"height"`
|
||||
Signature account.SignatureEd25519 `json:"signature"`
|
||||
Address []byte `json:"address"`
|
||||
Height int `json:"height"`
|
||||
Signature acm.SignatureEd25519 `json:"signature"`
|
||||
}
|
||||
|
||||
func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||
@ -282,9 +282,9 @@ func (tx *UnbondTx) String() string {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type RebondTx struct {
|
||||
Address []byte `json:"address"`
|
||||
Height int `json:"height"`
|
||||
Signature account.SignatureEd25519 `json:"signature"`
|
||||
Address []byte `json:"address"`
|
||||
Height int `json:"height"`
|
||||
Signature acm.SignatureEd25519 `json:"signature"`
|
||||
}
|
||||
|
||||
func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||
@ -316,7 +316,7 @@ func (tx *DupeoutTx) String() string {
|
||||
|
||||
// This should match the leaf hashes of Block.Data.Hash()'s SimpleMerkleTree.
|
||||
func TxID(chainID string, tx Tx) []byte {
|
||||
signBytes := account.SignBytes(chainID, tx)
|
||||
signBytes := acm.SignBytes(chainID, tx)
|
||||
return binary.BinaryRipemd160(signBytes)
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
_ "github.com/tendermint/tendermint/config/tendermint_test"
|
||||
)
|
||||
@ -39,7 +39,7 @@ func TestSendTxSignable(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
signBytes := account.SignBytes(chainID, sendTx)
|
||||
signBytes := acm.SignBytes(chainID, sendTx)
|
||||
signStr := string(signBytes)
|
||||
expected := Fmt(`{"chain_id":"%s","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
|
||||
config.GetString("chain_id"))
|
||||
@ -60,7 +60,7 @@ func TestCallTxSignable(t *testing.T) {
|
||||
Fee: 222,
|
||||
Data: []byte("data1"),
|
||||
}
|
||||
signBytes := account.SignBytes(chainID, callTx)
|
||||
signBytes := acm.SignBytes(chainID, callTx)
|
||||
signStr := string(signBytes)
|
||||
expected := Fmt(`{"chain_id":"%s","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
|
||||
config.GetString("chain_id"))
|
||||
@ -73,9 +73,9 @@ func TestBondTxSignable(t *testing.T) {
|
||||
privKeyBytes := make([]byte, 64)
|
||||
var privKeyArray [64]byte
|
||||
copy(privKeyArray[:], privKeyBytes)
|
||||
privAccount := account.GenPrivAccountFromPrivKeyBytes(&privKeyArray)
|
||||
privAccount := acm.GenPrivAccountFromPrivKeyBytes(&privKeyArray)
|
||||
bondTx := &BondTx{
|
||||
PubKey: privAccount.PubKey.(account.PubKeyEd25519),
|
||||
PubKey: privAccount.PubKey.(acm.PubKeyEd25519),
|
||||
Inputs: []*TxInput{
|
||||
&TxInput{
|
||||
Address: []byte("input1"),
|
||||
@ -99,7 +99,7 @@ func TestBondTxSignable(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
signBytes := account.SignBytes(chainID, bondTx)
|
||||
signBytes := acm.SignBytes(chainID, bondTx)
|
||||
signStr := string(signBytes)
|
||||
expected := Fmt(`{"chain_id":"%s","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
|
||||
config.GetString("chain_id"))
|
||||
@ -113,7 +113,7 @@ func TestUnbondTxSignable(t *testing.T) {
|
||||
Address: []byte("address1"),
|
||||
Height: 111,
|
||||
}
|
||||
signBytes := account.SignBytes(chainID, unbondTx)
|
||||
signBytes := acm.SignBytes(chainID, unbondTx)
|
||||
signStr := string(signBytes)
|
||||
expected := Fmt(`{"chain_id":"%s","tx":[18,{"address":"6164647265737331","height":111}]}`,
|
||||
config.GetString("chain_id"))
|
||||
@ -127,7 +127,7 @@ func TestRebondTxSignable(t *testing.T) {
|
||||
Address: []byte("address1"),
|
||||
Height: 111,
|
||||
}
|
||||
signBytes := account.SignBytes(chainID, rebondTx)
|
||||
signBytes := acm.SignBytes(chainID, rebondTx)
|
||||
signStr := string(signBytes)
|
||||
expected := Fmt(`{"chain_id":"%s","tx":[19,{"address":"6164647265737331","height":111}]}`,
|
||||
config.GetString("chain_id"))
|
||||
|
@ -2,11 +2,11 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
)
|
||||
|
||||
type AccountGetter interface {
|
||||
GetAccount(addr []byte) *account.Account
|
||||
GetAccount(addr []byte) *acm.Account
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@ -19,7 +19,7 @@ func NewSendTx() *SendTx {
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *SendTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) error {
|
||||
func (tx *SendTx) AddInput(st AccountGetter, pubkey acm.PubKey, amt int64) error {
|
||||
addr := pubkey.Address()
|
||||
acc := st.GetAccount(addr)
|
||||
if acc == nil {
|
||||
@ -28,13 +28,13 @@ func (tx *SendTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) e
|
||||
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
|
||||
}
|
||||
|
||||
func (tx *SendTx) AddInputWithNonce(pubkey account.PubKey, amt int64, nonce int) error {
|
||||
func (tx *SendTx) AddInputWithNonce(pubkey acm.PubKey, amt int64, nonce int) error {
|
||||
addr := pubkey.Address()
|
||||
tx.Inputs = append(tx.Inputs, &TxInput{
|
||||
Address: addr,
|
||||
Amount: amt,
|
||||
Sequence: nonce,
|
||||
Signature: account.SignatureEd25519{},
|
||||
Signature: acm.SignatureEd25519{},
|
||||
PubKey: pubkey,
|
||||
})
|
||||
return nil
|
||||
@ -48,7 +48,7 @@ func (tx *SendTx) AddOutput(addr []byte, amt int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *SendTx) SignInput(chainID string, i int, privAccount *account.PrivAccount) error {
|
||||
func (tx *SendTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error {
|
||||
if i >= len(tx.Inputs) {
|
||||
return fmt.Errorf("Index %v is greater than number of inputs (%v)", i, len(tx.Inputs))
|
||||
}
|
||||
@ -60,7 +60,7 @@ func (tx *SendTx) SignInput(chainID string, i int, privAccount *account.PrivAcco
|
||||
//----------------------------------------------------------------------------
|
||||
// CallTx interface for creating tx
|
||||
|
||||
func NewCallTx(st AccountGetter, from account.PubKey, to, data []byte, amt, gasLimit, fee int64) (*CallTx, error) {
|
||||
func NewCallTx(st AccountGetter, from acm.PubKey, to, data []byte, amt, gasLimit, fee int64) (*CallTx, error) {
|
||||
addr := from.Address()
|
||||
acc := st.GetAccount(addr)
|
||||
if acc == nil {
|
||||
@ -71,13 +71,13 @@ func NewCallTx(st AccountGetter, from account.PubKey, to, data []byte, amt, gasL
|
||||
return NewCallTxWithNonce(from, to, data, amt, gasLimit, fee, nonce), nil
|
||||
}
|
||||
|
||||
func NewCallTxWithNonce(from account.PubKey, to, data []byte, amt, gasLimit, fee int64, nonce int) *CallTx {
|
||||
func NewCallTxWithNonce(from acm.PubKey, to, data []byte, amt, gasLimit, fee int64, nonce int) *CallTx {
|
||||
addr := from.Address()
|
||||
input := &TxInput{
|
||||
Address: addr,
|
||||
Amount: amt,
|
||||
Sequence: nonce,
|
||||
Signature: account.SignatureEd25519{},
|
||||
Signature: acm.SignatureEd25519{},
|
||||
PubKey: from,
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ func NewCallTxWithNonce(from account.PubKey, to, data []byte, amt, gasLimit, fee
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *CallTx) Sign(chainID string, privAccount *account.PrivAccount) {
|
||||
func (tx *CallTx) Sign(chainID string, privAccount *acm.PrivAccount) {
|
||||
tx.Input.PubKey = privAccount.PubKey
|
||||
tx.Input.Signature = privAccount.Sign(chainID, tx)
|
||||
}
|
||||
@ -98,7 +98,7 @@ func (tx *CallTx) Sign(chainID string, privAccount *account.PrivAccount) {
|
||||
//----------------------------------------------------------------------------
|
||||
// NameTx interface for creating tx
|
||||
|
||||
func NewNameTx(st AccountGetter, from account.PubKey, name, data string, amt, fee int64) (*NameTx, error) {
|
||||
func NewNameTx(st AccountGetter, from acm.PubKey, name, data string, amt, fee int64) (*NameTx, error) {
|
||||
addr := from.Address()
|
||||
acc := st.GetAccount(addr)
|
||||
if acc == nil {
|
||||
@ -109,13 +109,13 @@ func NewNameTx(st AccountGetter, from account.PubKey, name, data string, amt, fe
|
||||
return NewNameTxWithNonce(from, name, data, amt, fee, nonce), nil
|
||||
}
|
||||
|
||||
func NewNameTxWithNonce(from account.PubKey, name, data string, amt, fee int64, nonce int) *NameTx {
|
||||
func NewNameTxWithNonce(from acm.PubKey, name, data string, amt, fee int64, nonce int) *NameTx {
|
||||
addr := from.Address()
|
||||
input := &TxInput{
|
||||
Address: addr,
|
||||
Amount: amt,
|
||||
Sequence: nonce,
|
||||
Signature: account.SignatureEd25519{},
|
||||
Signature: acm.SignatureEd25519{},
|
||||
PubKey: from,
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ func NewNameTxWithNonce(from account.PubKey, name, data string, amt, fee int64,
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *NameTx) Sign(chainID string, privAccount *account.PrivAccount) {
|
||||
func (tx *NameTx) Sign(chainID string, privAccount *acm.PrivAccount) {
|
||||
tx.Input.PubKey = privAccount.PubKey
|
||||
tx.Input.Signature = privAccount.Sign(chainID, tx)
|
||||
}
|
||||
@ -135,8 +135,8 @@ func (tx *NameTx) Sign(chainID string, privAccount *account.PrivAccount) {
|
||||
//----------------------------------------------------------------------------
|
||||
// BondTx interface for adding inputs/outputs and adding signatures
|
||||
|
||||
func NewBondTx(pubkey account.PubKey) (*BondTx, error) {
|
||||
pubkeyEd, ok := pubkey.(account.PubKeyEd25519)
|
||||
func NewBondTx(pubkey acm.PubKey) (*BondTx, error) {
|
||||
pubkeyEd, ok := pubkey.(acm.PubKeyEd25519)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Pubkey must be ed25519")
|
||||
}
|
||||
@ -147,7 +147,7 @@ func NewBondTx(pubkey account.PubKey) (*BondTx, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (tx *BondTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) error {
|
||||
func (tx *BondTx) AddInput(st AccountGetter, pubkey acm.PubKey, amt int64) error {
|
||||
addr := pubkey.Address()
|
||||
acc := st.GetAccount(addr)
|
||||
if acc == nil {
|
||||
@ -156,13 +156,13 @@ func (tx *BondTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) e
|
||||
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
|
||||
}
|
||||
|
||||
func (tx *BondTx) AddInputWithNonce(pubkey account.PubKey, amt int64, nonce int) error {
|
||||
func (tx *BondTx) AddInputWithNonce(pubkey acm.PubKey, amt int64, nonce int) error {
|
||||
addr := pubkey.Address()
|
||||
tx.Inputs = append(tx.Inputs, &TxInput{
|
||||
Address: addr,
|
||||
Amount: amt,
|
||||
Sequence: nonce,
|
||||
Signature: account.SignatureEd25519{},
|
||||
Signature: acm.SignatureEd25519{},
|
||||
PubKey: pubkey,
|
||||
})
|
||||
return nil
|
||||
@ -176,9 +176,9 @@ func (tx *BondTx) AddOutput(addr []byte, amt int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *BondTx) SignBond(chainID string, privAccount *account.PrivAccount) error {
|
||||
func (tx *BondTx) SignBond(chainID string, privAccount *acm.PrivAccount) error {
|
||||
sig := privAccount.Sign(chainID, tx)
|
||||
sigEd, ok := sig.(account.SignatureEd25519)
|
||||
sigEd, ok := sig.(acm.SignatureEd25519)
|
||||
if !ok {
|
||||
return fmt.Errorf("Bond signer must be ED25519")
|
||||
}
|
||||
@ -186,7 +186,7 @@ func (tx *BondTx) SignBond(chainID string, privAccount *account.PrivAccount) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *BondTx) SignInput(chainID string, i int, privAccount *account.PrivAccount) error {
|
||||
func (tx *BondTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error {
|
||||
if i >= len(tx.Inputs) {
|
||||
return fmt.Errorf("Index %v is greater than number of inputs (%v)", i, len(tx.Inputs))
|
||||
}
|
||||
@ -205,8 +205,8 @@ func NewUnbondTx(addr []byte, height int) *UnbondTx {
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *UnbondTx) Sign(chainID string, privAccount *account.PrivAccount) {
|
||||
tx.Signature = privAccount.Sign(chainID, tx).(account.SignatureEd25519)
|
||||
func (tx *UnbondTx) Sign(chainID string, privAccount *acm.PrivAccount) {
|
||||
tx.Signature = privAccount.Sign(chainID, tx).(acm.SignatureEd25519)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -219,6 +219,6 @@ func NewRebondTx(addr []byte, height int) *RebondTx {
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *RebondTx) Sign(chainID string, privAccount *account.PrivAccount) {
|
||||
tx.Signature = privAccount.Sign(chainID, tx).(account.SignatureEd25519)
|
||||
func (tx *RebondTx) Sign(chainID string, privAccount *acm.PrivAccount) {
|
||||
tx.Signature = privAccount.Sign(chainID, tx).(acm.SignatureEd25519)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
)
|
||||
@ -28,12 +28,12 @@ func (err *ErrVoteConflictingSignature) Error() string {
|
||||
|
||||
// Represents a prevote, precommit, or commit vote from validators for consensus.
|
||||
type Vote struct {
|
||||
Height int `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Type byte `json:"type"`
|
||||
BlockHash []byte `json:"block_hash"` // empty if vote is nil.
|
||||
BlockParts PartSetHeader `json:"block_parts"` // zero if vote is nil.
|
||||
Signature account.SignatureEd25519 `json:"signature"`
|
||||
Height int `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Type byte `json:"type"`
|
||||
BlockHash []byte `json:"block_hash"` // empty if vote is nil.
|
||||
BlockParts PartSetHeader `json:"block_parts"` // zero if vote is nil.
|
||||
Signature acm.SignatureEd25519 `json:"signature"`
|
||||
}
|
||||
|
||||
// Types of votes
|
||||
|
Loading…
x
Reference in New Issue
Block a user