mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-05 23:57:04 +00:00
pass chainID through sign interfaces
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ func BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
|
||||
return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
|
||||
}
|
||||
|
||||
txHash := types.TxId(tx)
|
||||
txHash := types.TxId(mempoolReactor.Mempool.GetState().ChainID, tx)
|
||||
var createsContract uint8
|
||||
var contractAddr []byte
|
||||
// check if creates new contract
|
||||
|
||||
+3
-2
@@ -66,7 +66,8 @@ func NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||
func Genesis() (*string, error) {
|
||||
b, err := ioutil.ReadFile(config.GetString("genesis_file"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
return &string(b), nil
|
||||
ret := string(b)
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
+6
-6
@@ -91,27 +91,27 @@ func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseS
|
||||
sendTx := tx.(*types.SendTx)
|
||||
for i, input := range sendTx.Inputs {
|
||||
input.PubKey = privAccounts[i].PubKey
|
||||
input.Signature = privAccounts[i].Sign(sendTx)
|
||||
input.Signature = privAccounts[i].Sign(config.GetString("chain_id"), sendTx)
|
||||
}
|
||||
case *types.CallTx:
|
||||
callTx := tx.(*types.CallTx)
|
||||
callTx.Input.PubKey = privAccounts[0].PubKey
|
||||
callTx.Input.Signature = privAccounts[0].Sign(callTx)
|
||||
callTx.Input.Signature = privAccounts[0].Sign(config.GetString("chain_id"), callTx)
|
||||
case *types.BondTx:
|
||||
bondTx := tx.(*types.BondTx)
|
||||
// the first privaccount corresponds to the BondTx pub key.
|
||||
// the rest to the inputs
|
||||
bondTx.Signature = privAccounts[0].Sign(bondTx).(account.SignatureEd25519)
|
||||
bondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), bondTx).(account.SignatureEd25519)
|
||||
for i, input := range bondTx.Inputs {
|
||||
input.PubKey = privAccounts[i+1].PubKey
|
||||
input.Signature = privAccounts[i+1].Sign(bondTx)
|
||||
input.Signature = privAccounts[i+1].Sign(config.GetString("chain_id"), bondTx)
|
||||
}
|
||||
case *types.UnbondTx:
|
||||
unbondTx := tx.(*types.UnbondTx)
|
||||
unbondTx.Signature = privAccounts[0].Sign(unbondTx).(account.SignatureEd25519)
|
||||
unbondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), unbondTx).(account.SignatureEd25519)
|
||||
case *types.RebondTx:
|
||||
rebondTx := tx.(*types.RebondTx)
|
||||
rebondTx.Signature = privAccounts[0].Sign(rebondTx).(account.SignatureEd25519)
|
||||
rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(account.SignatureEd25519)
|
||||
}
|
||||
return &ctypes.ResponseSignTx{tx}, nil
|
||||
}
|
||||
|
||||
@@ -193,6 +193,6 @@ func TestWSCallCall(t *testing.T) {
|
||||
waitForEvent(t, con, eid1, true, func() {
|
||||
tx := makeDefaultCallTx(t, wsTyp, contractAddr2, nil, amt, gasLim, fee)
|
||||
broadcastTx(t, wsTyp, tx)
|
||||
*txid = account.HashSignBytes(tx)
|
||||
*txid = account.HashSignBytes(chainID, tx)
|
||||
}, unmarshalValidateCallCall(user[0].Address, returnVal, txid))
|
||||
}
|
||||
|
||||
+8
-4
@@ -32,6 +32,8 @@ var (
|
||||
userPriv = "C453604BD6480D5538B4C6FD2E3E314B5BCE518D75ADE4DA3DA85AB8ADFD819606FBAC4E285285D1D91FCBC7E91C780ADA11516F67462340B3980CE2B94940E8"
|
||||
user = makeUsers(2)
|
||||
|
||||
chainID string
|
||||
|
||||
clients = map[string]cclient.Client{
|
||||
"JSONRPC": cclient.NewClient(requestAddr, "JSONRPC"),
|
||||
"HTTP": cclient.NewClient(requestAddr, "HTTP"),
|
||||
@@ -74,6 +76,8 @@ func newNode(ready chan struct{}) {
|
||||
|
||||
// initialize config and create new node
|
||||
func init() {
|
||||
chainID = config.GetString("chain_id")
|
||||
|
||||
// Save new priv_validator file.
|
||||
priv := &state.PrivValidator{
|
||||
Address: user[0].Address,
|
||||
@@ -83,7 +87,7 @@ func init() {
|
||||
priv.SetFile(config.GetString("priv_validator_file"))
|
||||
priv.Save()
|
||||
|
||||
consensus.RoundDuration0 = 3 * time.Second
|
||||
consensus.RoundDuration0 = 2 * time.Second
|
||||
consensus.RoundDurationDelta = 1 * time.Second
|
||||
|
||||
// start a node
|
||||
@@ -105,14 +109,14 @@ func makeDefaultSendTx(t *testing.T, typ string, addr []byte, amt uint64) *types
|
||||
|
||||
func makeDefaultSendTxSigned(t *testing.T, typ string, addr []byte, amt uint64) *types.SendTx {
|
||||
tx := makeDefaultSendTx(t, typ, addr, amt)
|
||||
tx.SignInput(0, user[0])
|
||||
tx.SignInput(chainID, 0, user[0])
|
||||
return tx
|
||||
}
|
||||
|
||||
func makeDefaultCallTx(t *testing.T, typ string, addr, code []byte, amt, gasLim, fee uint64) *types.CallTx {
|
||||
nonce := getNonce(t, typ, user[0].Address)
|
||||
tx := types.NewCallTxWithNonce(user[0].PubKey, addr, code, amt, gasLim, fee, nonce)
|
||||
tx.Sign(user[0])
|
||||
tx.Sign(chainID, user[0])
|
||||
return tx
|
||||
}
|
||||
|
||||
@@ -214,7 +218,7 @@ func checkTx(t *testing.T, fromAddr []byte, priv *account.PrivAccount, tx *types
|
||||
t.Fatal("Tx input addresses don't match!")
|
||||
}
|
||||
|
||||
signBytes := account.SignBytes(tx)
|
||||
signBytes := account.SignBytes(chainID, tx)
|
||||
in := tx.Inputs[0] //(*types.SendTx).Inputs[0]
|
||||
|
||||
if err := in.ValidateBasic(); err != nil {
|
||||
|
||||
+7
-7
@@ -15,9 +15,9 @@ func testStatus(t *testing.T, typ string) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resp.ChainID != config.GetString("chain_id") {
|
||||
if resp.ChainID != chainID {
|
||||
t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s",
|
||||
resp.ChainID, config.Get("chain_id")))
|
||||
resp.ChainID, chainID))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,9 +57,9 @@ func testSignedTx(t *testing.T, typ string) {
|
||||
func testOneSignTx(t *testing.T, typ string, addr []byte, amt uint64) {
|
||||
tx := makeDefaultSendTx(t, typ, addr, amt)
|
||||
tx2 := signTx(t, typ, tx, user[0])
|
||||
tx2hash := account.HashSignBytes(tx2)
|
||||
tx.SignInput(0, user[0])
|
||||
txhash := account.HashSignBytes(tx)
|
||||
tx2hash := account.HashSignBytes(chainID, tx2)
|
||||
tx.SignInput(chainID, 0, user[0])
|
||||
txhash := account.HashSignBytes(chainID, tx)
|
||||
if bytes.Compare(txhash, tx2hash) != 0 {
|
||||
t.Fatal("Got different signatures for signing via rpc vs tx_utils")
|
||||
}
|
||||
@@ -88,8 +88,8 @@ func testBroadcastTx(t *testing.T, typ string) {
|
||||
tx2 := txs[mempoolCount-1].(*types.SendTx)
|
||||
n, err := new(int64), new(error)
|
||||
buf1, buf2 := new(bytes.Buffer), new(bytes.Buffer)
|
||||
tx.WriteSignBytes(buf1, n, err)
|
||||
tx2.WriteSignBytes(buf2, n, err)
|
||||
tx.WriteSignBytes(chainID, buf1, n, err)
|
||||
tx2.WriteSignBytes(chainID, buf2, n, err)
|
||||
if bytes.Compare(buf1.Bytes(), buf2.Bytes()) != 0 {
|
||||
t.Fatal("inconsistent hashes for mempool tx and sent tx")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user