Made all JSON fields lower_case

This commit is contained in:
Jae Kwon
2015-05-01 17:26:49 -07:00
parent 9babda1d7a
commit b92c0401e6
26 changed files with 323 additions and 265 deletions
+16 -16
View File
@@ -16,9 +16,9 @@ import (
)
type Block struct {
*Header
*Validation
*Data
*Header `json:"header"`
*Validation `json:"validation"`
*Data `json:"data"`
}
// Basic validation that doesn't involve state data.
@@ -123,14 +123,14 @@ func (b *Block) StringShort() string {
//-----------------------------------------------------------------------------
type Header struct {
Network string
Height uint
Time time.Time
Fees uint64
NumTxs uint
LastBlockHash []byte
LastBlockParts PartSetHeader
StateHash []byte
Network string `json:"network"`
Height uint `json:"height"`
Time time.Time `json:"time"`
Fees uint64 `json:"fees"`
NumTxs uint `json:"num_txs"`
LastBlockHash []byte `json:"last_block_hash"`
LastBlockParts PartSetHeader `json:"last_block_parts"`
StateHash []byte `json:"state_hash"`
}
// NOTE: hash is nil if required fields are missing.
@@ -178,9 +178,9 @@ func (h *Header) StringIndented(indent string) string {
//-----------------------------------------------------------------------------
type Commit struct {
Address []byte
Round uint
Signature account.SignatureEd25519
Address []byte `json:"address"`
Round uint `json:"round"`
Signature account.SignatureEd25519 `json:"signature"`
}
func (commit Commit) IsZero() bool {
@@ -197,7 +197,7 @@ func (commit Commit) String() string {
// Any peer with a block can gossip commits by index with a peer without recalculating the
// active ValidatorSet.
type Validation struct {
Commits []Commit // Commits (or nil) of all active validators in address order.
Commits []Commit `json:"commits"` // Commits (or nil) of all active validators in address order.
// Volatile
hash []byte
@@ -267,7 +267,7 @@ func (v *Validation) BitArray() BitArray {
//-----------------------------------------------------------------------------
type Data struct {
Txs []Tx
Txs []Tx `json:"txs"`
// Volatile
hash []byte
+3 -3
View File
@@ -1,9 +1,9 @@
package types
type BlockMeta struct {
Hash []byte // The block hash
Header *Header // The block's Header
Parts PartSetHeader // The PartSetHeader, for transfer
Hash []byte `json:"hash"` // The block hash
Header *Header `json:"header"` // The block's Header
Parts PartSetHeader `json:"parts"` // The PartSetHeader, for transfer
}
func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {
+16 -16
View File
@@ -7,15 +7,15 @@ import (
// Functions to generate eventId strings
func EventStringAccInput(addr []byte) string {
return fmt.Sprintf("Acc/%x/Input", addr)
return fmt.Sprintf("Acc/%X/Input", addr)
}
func EventStringAccOutput(addr []byte) string {
return fmt.Sprintf("Acc/%x/Output", addr)
return fmt.Sprintf("Acc/%X/Output", addr)
}
func EventStringAccReceive(addr []byte) string {
return fmt.Sprintf("Acc/%x/Receive", addr)
return fmt.Sprintf("Acc/%X/Receive", addr)
}
func EventStringBond() string {
@@ -46,25 +46,25 @@ func EventStringFork() string {
// but some (an input to a call tx or a receive) are more exotic:
type EventMsgCallTx struct {
Tx Tx
Return []byte
Exception string
Tx Tx `json:"tx"`
Return []byte `json:"return"`
Exception string `json:"exception"`
}
type CallData struct {
Caller []byte
Callee []byte
Data []byte
Value uint64
Gas uint64
Caller []byte `json:"caller"`
Callee []byte `json:"callee"`
Data []byte `json:"data"`
Value uint64 `json:"value"`
Gas uint64 `json:"gas"`
}
type EventMsgCall struct {
CallData *CallData
Origin []byte
TxId []byte
Return []byte
Exception string
CallData *CallData `json:"call_data"`
Origin []byte `json:"origin"`
TxId []byte `json:"tx_id"`
Return []byte `json:"return"`
Exception string `json:"exception"`
}
/*
+6 -6
View File
@@ -6,13 +6,13 @@ import (
)
type NodeInfo struct {
Moniker string
Network string
Version string
Moniker string `json:"moniker"`
Network string `json:"network"`
Version string `json:"version"`
Host string
P2PPort uint16
RPCPort uint16
Host string `json:"host"`
P2PPort uint16 `json:"p2p_port"`
RPCPort uint16 `json:"rpc_port"`
}
func (ni *NodeInfo) CompatibleWith(no *NodeInfo) error {
+6 -6
View File
@@ -24,9 +24,9 @@ var (
)
type Part struct {
Index uint
Trail [][]byte
Bytes []byte
Index uint `json:"index"`
Trail [][]byte `json:"trail"`
Bytes []byte `json:"bytes"`
// Cache
hash []byte
@@ -69,8 +69,8 @@ func (part *Part) StringIndented(indent string) string {
//-------------------------------------
type PartSetHeader struct {
Total uint
Hash []byte
Total uint `json:"total"`
Hash []byte `json:"hash"`
}
func (psh PartSetHeader) String() string {
@@ -86,7 +86,7 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
}
func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteTo([]byte(Fmt(`{"Hash":"%X","Total":%v}`, psh.Hash, psh.Total)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"hash":"%X","total":%v}`, psh.Hash, psh.Total)), w, n, err)
}
//-------------------------------------
+42 -42
View File
@@ -73,11 +73,11 @@ var _ = binary.RegisterInterface(
//-----------------------------------------------------------------------------
type TxInput struct {
Address []byte // Hash of the PubKey
Amount uint64 // Must not exceed account balance
Sequence uint // Must be 1 greater than the last committed TxInput
Signature account.Signature // Depends on the PubKey type and the whole Tx
PubKey account.PubKey // Must not be nil, may be nil
Address []byte `json:"address"` // Hash of the PubKey
Amount uint64 `json:"amount"` // Must not exceed account balance
Sequence uint `json:"sequence"` // Must be 1 greater than the last committed TxInput
Signature account.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
PubKey account.PubKey `json:"pub_key"` // Must not be nil, may be nil
}
func (txIn *TxInput) ValidateBasic() error {
@@ -91,7 +91,7 @@ func (txIn *TxInput) ValidateBasic() error {
}
func (txIn *TxInput) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteTo([]byte(Fmt(`{"Address":"%X","Amount":%v,"Sequence":%v}`, txIn.Address, txIn.Amount, txIn.Sequence)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v,"sequence":%v}`, txIn.Address, txIn.Amount, txIn.Sequence)), w, n, err)
}
func (txIn *TxInput) String() string {
@@ -101,8 +101,8 @@ func (txIn *TxInput) String() string {
//-----------------------------------------------------------------------------
type TxOutput struct {
Address []byte // Hash of the PubKey
Amount uint64 // The sum of all outputs must not exceed the inputs.
Address []byte `json:"address"` // Hash of the PubKey
Amount uint64 `json:"amount"` // The sum of all outputs must not exceed the inputs.
}
func (txOut *TxOutput) ValidateBasic() error {
@@ -116,7 +116,7 @@ func (txOut *TxOutput) ValidateBasic() error {
}
func (txOut *TxOutput) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteTo([]byte(Fmt(`{"Address":"%X","Amount":%v}`, txOut.Address, txOut.Amount)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v}`, txOut.Address, txOut.Amount)), w, n, err)
}
func (txOut *TxOutput) String() string {
@@ -126,21 +126,21 @@ func (txOut *TxOutput) String() string {
//-----------------------------------------------------------------------------
type SendTx struct {
Inputs []*TxInput
Outputs []*TxOutput
Inputs []*TxInput `json:"inputs"`
Outputs []*TxOutput `json:"outputs"`
}
func (tx *SendTx) WriteSignBytes(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"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Tx":[%v,{"Inputs":[`, TxTypeSend)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err)
for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err)
if i != len(tx.Inputs)-1 {
binary.WriteTo([]byte(","), w, n, err)
}
}
binary.WriteTo([]byte(`],"Outputs":[`), w, n, err)
binary.WriteTo([]byte(`],"outputs":[`), w, n, err)
for i, out := range tx.Outputs {
out.WriteSignBytes(w, n, err)
if i != len(tx.Outputs)-1 {
@@ -157,18 +157,18 @@ func (tx *SendTx) String() string {
//-----------------------------------------------------------------------------
type CallTx struct {
Input *TxInput
Address []byte
GasLimit uint64
Fee uint64
Data []byte
Input *TxInput `json:"input"`
Address []byte `json:"address"`
GasLimit uint64 `json:"gas_limit"`
Fee uint64 `json:"fee"`
Data []byte `json:"data"`
}
func (tx *CallTx) WriteSignBytes(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"`, config.App().GetString("Network"))), 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,"GasLimit":%v,"Input":`, tx.Fee, tx.GasLimit)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), 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)
tx.Input.WriteSignBytes(w, n, err)
binary.WriteTo([]byte(`}]}`), w, n, err)
}
@@ -180,24 +180,24 @@ func (tx *CallTx) String() string {
//-----------------------------------------------------------------------------
type BondTx struct {
PubKey account.PubKeyEd25519
Inputs []*TxInput
UnbondTo []*TxOutput
PubKey account.PubKeyEd25519 `json:"pub_key"`
Inputs []*TxInput `json:"inputs"`
UnbondTo []*TxOutput `json:"unbond_to"`
}
func (tx *BondTx) WriteSignBytes(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"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Tx":[%v,{"Inputs":[`, TxTypeBond)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err)
if i != len(tx.Inputs)-1 {
binary.WriteTo([]byte(","), w, n, err)
}
}
binary.WriteTo([]byte(Fmt(`],"PubKey":`)), w, n, err)
binary.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err)
binary.WriteTo(binary.JSONBytes(tx.PubKey), w, n, err)
binary.WriteTo([]byte(`,"UnbondTo":[`), w, n, err)
binary.WriteTo([]byte(`,"unbond_to":[`), w, n, err)
for i, out := range tx.UnbondTo {
out.WriteSignBytes(w, n, err)
if i != len(tx.UnbondTo)-1 {
@@ -214,15 +214,15 @@ func (tx *BondTx) String() string {
//-----------------------------------------------------------------------------
type UnbondTx struct {
Address []byte
Height uint
Signature account.SignatureEd25519
Address []byte `json:"address"`
Height uint `json:"height"`
Signature account.SignatureEd25519 `json:"signature"`
}
func (tx *UnbondTx) WriteSignBytes(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"`, config.App().GetString("Network"))), 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(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
}
func (tx *UnbondTx) String() string {
@@ -232,15 +232,15 @@ func (tx *UnbondTx) String() string {
//-----------------------------------------------------------------------------
type RebondTx struct {
Address []byte
Height uint
Signature account.SignatureEd25519
Address []byte `json:"address"`
Height uint `json:"height"`
Signature account.SignatureEd25519 `json:"signature"`
}
func (tx *RebondTx) WriteSignBytes(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"`, config.App().GetString("Network"))), 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(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
}
func (tx *RebondTx) String() string {
@@ -250,9 +250,9 @@ func (tx *RebondTx) String() string {
//-----------------------------------------------------------------------------
type DupeoutTx struct {
Address []byte
VoteA Vote
VoteB Vote
Address []byte `json:"address"`
VoteA Vote `json:"vote_a"`
VoteB Vote `json:"vote_b"`
}
func (tx *DupeoutTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
+5 -5
View File
@@ -35,7 +35,7 @@ func TestSendTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(sendTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%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(`{"network":"%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}]}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
@@ -56,7 +56,7 @@ func TestCallTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(callTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[2,{"Address":"636F6E747261637431","Data":"6461746131","Fee":222,"GasLimit":111,"Input":{"Address":"696E70757431","Amount":12345,"Sequence":67890}}]}`,
expected := Fmt(`{"network":"%X","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
@@ -92,7 +92,7 @@ func TestBondTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(bondTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[17,{"Inputs":[{"Address":"696E70757431","Amount":12345,"Sequence":67890},{"Address":"696E70757432","Amount":111,"Sequence":222}],"PubKey":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"UnbondTo":[{"Address":"6F757470757431","Amount":333},{"Address":"6F757470757432","Amount":444}]}]}`,
expected := Fmt(`{"network":"%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}]}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for BondTx")
@@ -106,7 +106,7 @@ func TestUnbondTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(unbondTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[18,{"Address":"6164647265737331","Height":111}]}`,
expected := Fmt(`{"network":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for UnbondTx")
@@ -120,7 +120,7 @@ func TestRebondTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(rebondTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[19,{"Address":"6164647265737331","Height":111}]}`,
expected := Fmt(`{"network":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for RebondTx")
+9 -9
View File
@@ -31,12 +31,12 @@ func (err *ErrVoteConflictingSignature) Error() string {
// Commit votes get aggregated into the next block's Validaiton.
// See the whitepaper for details.
type Vote struct {
Height uint
Round uint
Type byte
BlockHash []byte // empty if vote is nil.
BlockParts PartSetHeader // zero if vote is nil.
Signature account.SignatureEd25519
Height uint `json:"height"`
Round uint `json:"round"`
Type byte `json:"type"`
BlockHash []byte `json:"block_hash"` // empty if vote is nil.
BlockParts PartSetHeader `json:"block_parts"` // zero if vote is nil.
Signature account.SignatureEd25519 `json:"signature"`
}
// Types of votes
@@ -48,9 +48,9 @@ const (
func (vote *Vote) WriteSignBytes(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"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Vote":{"BlockHash":"%X","BlockParts":%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(`{"network":"%X"`, config.App().GetString("Network"))), 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)
}
func (vote *Vote) Copy() *Vote {