Actually set Input.Signature; Call rpc broadcast_tx_sync
This commit is contained in:
parent
436e0ba7d7
commit
01b2def693
|
@ -0,0 +1 @@
|
|||
*.swp
|
11
app/app.go
11
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, ""
|
||||
}
|
||||
|
|
|
@ -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(".")
|
||||
|
|
Loading…
Reference in New Issue