Browse Source

chain_id written as string not hex in WriteSignBytes

pull/83/head
Ethan Buchman 10 years ago
parent
commit
41502e05c1
6 changed files with 15 additions and 23 deletions
  1. +1
    -2
      consensus/types/proposal.go
  2. +1
    -1
      consensus/types/proposal_test.go
  3. +1
    -1
      types/names.go
  4. +6
    -12
      types/tx.go
  5. +5
    -5
      types/tx_test.go
  6. +1
    -2
      types/vote.go

+ 1
- 2
consensus/types/proposal.go View File

@ -39,8 +39,7 @@ func (p *Proposal) String() string {
} }
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the chain_id name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err) binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err)
p.BlockParts.WriteSignBytes(w, n, err) p.BlockParts.WriteSignBytes(w, n, err)
binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err) binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err)


+ 1
- 1
consensus/types/proposal_test.go View File

@ -19,7 +19,7 @@ func TestProposalSignable(t *testing.T) {
} }
signBytes := account.SignBytes(config.GetString("chain_id"), proposal) signBytes := account.SignBytes(config.GetString("chain_id"), proposal)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%X","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`,
expected := Fmt(`{"chain_id":"%s","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`,
config.GetString("chain_id")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr) t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)


+ 1
- 1
types/names.go View File

@ -38,7 +38,7 @@ func BaseEntryCost(name, data string) uint64 {
type NameRegEntry struct { type NameRegEntry struct {
Name string `json:"name"` // registered name for the entry Name string `json:"name"` // registered name for the entry
Owner []byte `json:"owner"` // address that created the entry Owner []byte `json:"owner"` // address that created the entry
Data string `json:"data"` // binary encoded byte array
Data string `json:"data"` // data to store under this name
Expires uint64 `json:"expires"` // block at which this entry expires Expires uint64 `json:"expires"` // block at which this entry expires
} }


+ 6
- 12
types/tx.go View File

@ -135,8 +135,7 @@ type SendTx struct {
} }
func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err)
for i, in := range tx.Inputs { for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err) in.WriteSignBytes(w, n, err)
@ -169,8 +168,7 @@ type CallTx struct {
} }
func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err) binary.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err)
tx.Input.WriteSignBytes(w, n, err) tx.Input.WriteSignBytes(w, n, err)
@ -191,8 +189,7 @@ type NameTx struct {
} }
func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"name":"%s","data":"%s"`, TxTypeName, tx.Name, tx.Data)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"name":"%s","data":"%s"`, TxTypeName, tx.Name, tx.Data)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"fee":%v,"input":`, tx.Fee)), w, n, err) binary.WriteTo([]byte(Fmt(`,"fee":%v,"input":`, tx.Fee)), w, n, err)
tx.Input.WriteSignBytes(w, n, err) tx.Input.WriteSignBytes(w, n, err)
@ -239,8 +236,7 @@ type BondTx struct {
} }
func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
for i, in := range tx.Inputs { for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err) in.WriteSignBytes(w, n, err)
@ -273,8 +269,7 @@ type UnbondTx struct {
} }
func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
} }
@ -291,8 +286,7 @@ type RebondTx struct {
} }
func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
} }


+ 5
- 5
types/tx_test.go View File

@ -41,7 +41,7 @@ func TestSendTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(chainID, sendTx) signBytes := account.SignBytes(chainID, sendTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%X","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
expected := Fmt(`{"chain_id":"%s","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr) t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
@ -62,7 +62,7 @@ func TestCallTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(chainID, callTx) signBytes := account.SignBytes(chainID, callTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%X","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
expected := Fmt(`{"chain_id":"%s","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr) t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
@ -98,7 +98,7 @@ func TestBondTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(chainID, bondTx) signBytes := account.SignBytes(chainID, bondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%X","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
expected := Fmt(`{"chain_id":"%s","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for BondTx") t.Errorf("Got unexpected sign string for BondTx")
@ -112,7 +112,7 @@ func TestUnbondTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(chainID, unbondTx) signBytes := account.SignBytes(chainID, unbondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`,
expected := Fmt(`{"chain_id":"%s","tx":[18,{"address":"6164647265737331","height":111}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for UnbondTx") t.Errorf("Got unexpected sign string for UnbondTx")
@ -126,7 +126,7 @@ func TestRebondTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(chainID, rebondTx) signBytes := account.SignBytes(chainID, rebondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`,
expected := Fmt(`{"chain_id":"%s","tx":[19,{"address":"6164647265737331","height":111}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for RebondTx") t.Errorf("Got unexpected sign string for RebondTx")


+ 1
- 2
types/vote.go View File

@ -46,8 +46,7 @@ const (
) )
func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
// We hex encode the chain_id name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err) binary.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err) binary.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
} }


Loading…
Cancel
Save