From 01b2def693b973afa7cfd6c887e166a1988dc2d3 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 8 Feb 2016 01:55:13 -0800 Subject: [PATCH] Actually set Input.Signature; Call rpc broadcast_tx_sync --- .gitignore | 1 + app/app.go | 11 ++++++++--- tests/tendermint/main.go | 10 +++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1377554eb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/app/app.go b/app/app.go index 2e23dc37b..cd21a7130 100644 --- a/app/app.go +++ b/app/app.go @@ -157,13 +157,18 @@ func validateTx(tx types.Tx) (code tmsp.CodeType, errStr string) { return tmsp.CodeType_OK, "" } -// NOTE: Tx is a struct, so it's copying the value func txSignBytes(tx types.Tx) []byte { + sigs := make([]crypto.Signature, len(tx.Inputs)) for i, input := range tx.Inputs { + sigs[i] = input.Signature input.Signature = nil tx.Inputs[i] = input } - return wire.BinaryBytes(tx) + signBytes := wire.BinaryBytes(tx) + for i := range tx.Inputs { + tx.Inputs[i].Signature = sigs[i] + } + return signBytes } func validateInput(input types.Input, signBytes []byte) (code tmsp.CodeType, errStr string) { @@ -174,7 +179,7 @@ func validateInput(input types.Input, signBytes []byte) (code tmsp.CodeType, err return tmsp.CodeType_EncodingError, "Input pubKey cannot be nil" } if !input.PubKey.VerifyBytes(signBytes, input.Signature) { - return tmsp.CodeType_Unauthorized, "Invalid ignature" + return tmsp.CodeType_Unauthorized, "Invalid signature" } return tmsp.CodeType_OK, "" } diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 34cc2f45e..835e42bfa 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -59,10 +59,18 @@ func main() { } sequence += 1 + // Sign request + signBytes := wire.BinaryBytes(tx) + fmt.Printf("SIGN: %X\n", signBytes) + sig := root.PrivKey.Sign(signBytes) + fmt.Println("VERIFY: ", root.PubKey.VerifyBytes(signBytes, sig)) + tx.Inputs[0].Signature = sig + //fmt.Println("tx:", tx) + // Write request txBytes := wire.BinaryBytes(tx) fmt.Println("tx:", hex.EncodeToString(txBytes)) - request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(txBytes)) + request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", Arr(txBytes)) reqBytes := wire.JSONBytes(request) fmt.Println("req:", hex.EncodeToString(reqBytes)) //fmt.Print(".")