Browse Source

add bonder's signature to BondTx

pull/70/head
Ethan Buchman 9 years ago
parent
commit
d43c776e84
4 changed files with 14 additions and 5 deletions
  1. +5
    -2
      rpc/core/txs.go
  2. +3
    -0
      state/execution.go
  3. +2
    -0
      state/state_test.go
  4. +4
    -3
      types/tx.go

+ 5
- 2
rpc/core/txs.go View File

@ -99,9 +99,12 @@ func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseS
callTx.Input.Signature = privAccounts[0].Sign(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)
for i, input := range bondTx.Inputs {
input.PubKey = privAccounts[i].PubKey
input.Signature = privAccounts[i].Sign(bondTx)
input.PubKey = privAccounts[i+1].PubKey
input.Signature = privAccounts[i+1].Sign(bondTx)
}
case *types.UnbondTx:
unbondTx := tx.(*types.UnbondTx)


+ 3
- 0
state/execution.go View File

@ -497,6 +497,9 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
if err := tx.PubKey.ValidateBasic(); err != nil {
return err
}
if !tx.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature
}
outTotal, err := validateOutputs(tx.UnbondTo)
if err != nil {
return err


+ 2
- 0
state/state_test.go View File

@ -288,6 +288,7 @@ func TestTxs(t *testing.T) {
},
},
}
tx.Signature = privAccounts[0].Sign(tx).(account.SignatureEd25519)
tx.Inputs[0].Signature = privAccounts[0].Sign(tx)
err := execTxWithState(state, tx, true)
if err != nil {
@ -344,6 +345,7 @@ func TestAddValidator(t *testing.T) {
},
},
}
bondTx.Signature = acc0.Sign(bondTx).(account.SignatureEd25519)
bondTx.Inputs[0].Signature = acc0.Sign(bondTx)
// Make complete block and blockParts


+ 4
- 3
types/tx.go View File

@ -179,9 +179,10 @@ func (tx *CallTx) String() string {
//-----------------------------------------------------------------------------
type BondTx struct {
PubKey account.PubKeyEd25519 `json:"pub_key"`
Inputs []*TxInput `json:"inputs"`
UnbondTo []*TxOutput `json:"unbond_to"`
PubKey account.PubKeyEd25519 `json:"pub_key"`
Signature account.SignatureEd25519 `json:"signature"`
Inputs []*TxInput `json:"inputs"`
UnbondTo []*TxOutput `json:"unbond_to"`
}
func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {


Loading…
Cancel
Save