From 16de80fa7e8e3df0f99388e5833b69c046d61bfd Mon Sep 17 00:00:00 2001
From: Ethan Buchman <ethan@coinculture.info>
Date: Fri, 26 Feb 2016 15:29:14 +0000
Subject: [PATCH] give dupeouttx signbytes (for txid)

---
 .../tendermint/tendermint/types/tx.go         |  3 +-
 .../tendermint/tendermint/types/tx_test.go    | 31 +++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx.go b/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx.go
index ff2534e5..00c3314e 100644
--- a/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx.go
+++ b/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx.go
@@ -328,7 +328,8 @@ type DupeoutTx struct {
 }
 
 func (tx *DupeoutTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
-	PanicSanity("DupeoutTx has no sign bytes")
+	wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
+	wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","vote_a":%v,"vote_b":%v}]}`, TxTypeDupeout, tx.Address, tx.VoteA, tx.VoteB)), w, n, err)
 }
 
 func (tx *DupeoutTx) String() string {
diff --git a/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx_test.go b/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx_test.go
index ad6fb584..46c60c93 100644
--- a/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx_test.go
+++ b/Godeps/_workspace/src/github.com/tendermint/tendermint/types/tx_test.go
@@ -176,3 +176,34 @@ func TestPermissionsTxSignable(t *testing.T) {
 		t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
 	}
 }
+
+func TestDupeoutTxSignable(t *testing.T) {
+	privAcc := acm.GenPrivAccount()
+	partSetHeader := PartSetHeader{Total: 10, Hash: []byte("partsethash")}
+	voteA := &Vote{
+		Height:           10,
+		Round:            2,
+		Type:             VoteTypePrevote,
+		BlockHash:        []byte("myblockhash"),
+		BlockPartsHeader: partSetHeader,
+	}
+	sig := privAcc.Sign(chainID, voteA)
+	voteA.Signature = sig.(acm.SignatureEd25519)
+	voteB := voteA.Copy()
+	voteB.BlockHash = []byte("myotherblockhash")
+	sig = privAcc.Sign(chainID, voteB)
+	voteB.Signature = sig.(acm.SignatureEd25519)
+
+	dupeoutTx := &DupeoutTx{
+		Address: []byte("address1"),
+		VoteA:   *voteA,
+		VoteB:   *voteB,
+	}
+	signBytes := acm.SignBytes(chainID, dupeoutTx)
+	signStr := string(signBytes)
+	expected := Fmt(`{"chain_id":"%s","tx":[20,{"address":"6164647265737331","vote_a":%v,"vote_b":%v}]}`,
+		config.GetString("chain_id"), *voteA, *voteB)
+	if signStr != expected {
+		t.Errorf("Got unexpected sign string for DupeoutTx")
+	}
+}
-- 
GitLab