diff --git a/account/account.go b/account/account.go index 175a7bb94..97af5e050 100644 --- a/account/account.go +++ b/account/account.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/merkle" ptypes "github.com/tendermint/tendermint/permission/types" @@ -36,7 +36,7 @@ func HashSignBytes(chainID string, o Signable) []byte { // Account resides in the application state, and is mutated by transactions // on the blockchain. -// Serialized by binary.[read|write]Reflect +// Serialized by wire.[read|write]Reflect type Account struct { Address []byte `json:"address"` PubKey PubKey `json:"pub_key"` @@ -61,14 +61,14 @@ func (acc *Account) String() string { } func AccountEncoder(o interface{}, w io.Writer, n *int64, err *error) { - binary.WriteBinary(o.(*Account), w, n, err) + wire.WriteBinary(o.(*Account), w, n, err) } func AccountDecoder(r io.Reader, n *int64, err *error) interface{} { - return binary.ReadBinary(&Account{}, r, n, err) + return wire.ReadBinary(&Account{}, r, n, err) } -var AccountCodec = binary.Codec{ +var AccountCodec = wire.Codec{ Encode: AccountEncoder, Decode: AccountDecoder, } diff --git a/account/priv_account.go b/account/priv_account.go index c97d03940..9310d9d53 100644 --- a/account/priv_account.go +++ b/account/priv_account.go @@ -2,7 +2,7 @@ package account import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -49,7 +49,7 @@ func GenPrivAccount() *PrivAccount { // Generates a new account with private key from SHA256 hash of a secret func GenPrivAccountFromSecret(secret []byte) *PrivAccount { - privKey32 := binary.BinarySha256(secret) // Not Ripemd160 because we want 32 bytes. + privKey32 := wire.BinarySha256(secret) // Not Ripemd160 because we want 32 bytes. privKeyBytes := new([64]byte) copy(privKeyBytes[:32], privKey32) pubKeyBytes := ed25519.MakePublicKey(privKeyBytes) diff --git a/account/priv_key.go b/account/priv_key.go index c3eb5027f..87b65821c 100644 --- a/account/priv_key.go +++ b/account/priv_key.go @@ -3,7 +3,7 @@ package account import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519" "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -18,10 +18,10 @@ const ( PrivKeyTypeEd25519 = byte(0x01) ) -// for binary.readReflect -var _ = binary.RegisterInterface( +// for wire.readReflect +var _ = wire.RegisterInterface( struct{ PrivKey }{}, - binary.ConcreteType{PrivKeyEd25519{}, PrivKeyTypeEd25519}, + wire.ConcreteType{PrivKeyEd25519{}, PrivKeyTypeEd25519}, ) //------------------------------------- @@ -53,7 +53,7 @@ func (privKey PrivKeyEd25519) String() string { // Deterministically generates new priv-key bytes from key. func (key PrivKeyEd25519) Generate(index int) PrivKeyEd25519 { - newBytes := binary.BinarySha256(struct { + newBytes := wire.BinarySha256(struct { PrivKey [64]byte Index int }{key, index}) diff --git a/account/pub_key.go b/account/pub_key.go index 1a307989b..c83c1e2b1 100644 --- a/account/pub_key.go +++ b/account/pub_key.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519" "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519" "github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -21,10 +21,10 @@ const ( PubKeyTypeEd25519 = byte(0x01) ) -// for binary.readReflect -var _ = binary.RegisterInterface( +// for wire.readReflect +var _ = wire.RegisterInterface( struct{ PubKey }{}, - binary.ConcreteType{PubKeyEd25519{}, PubKeyTypeEd25519}, + wire.ConcreteType{PubKeyEd25519{}, PubKeyTypeEd25519}, ) //------------------------------------- @@ -38,7 +38,7 @@ type PubKeyEd25519 [32]byte // compatibility for when the pubkey wasn't fixed length array func (pubKey PubKeyEd25519) Address() []byte { w, n, err := new(bytes.Buffer), new(int64), new(error) - binary.WriteBinary(pubKey[:], w, n, err) + wire.WriteBinary(pubKey[:], w, n, err) if *err != nil { PanicCrisis(*err) } diff --git a/account/signature.go b/account/signature.go index a858cb0fd..fbf3cdda0 100644 --- a/account/signature.go +++ b/account/signature.go @@ -3,7 +3,7 @@ package account import ( "fmt" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -18,10 +18,10 @@ const ( SignatureTypeEd25519 = byte(0x01) ) -// for binary.readReflect -var _ = binary.RegisterInterface( +// for wire.readReflect +var _ = wire.RegisterInterface( struct{ Signature }{}, - binary.ConcreteType{SignatureEd25519{}, SignatureTypeEd25519}, + wire.ConcreteType{SignatureEd25519{}, SignatureTypeEd25519}, ) //------------------------------------- diff --git a/account/signature_test.go b/account/signature_test.go index 4a64b94a4..b9d456588 100644 --- a/account/signature_test.go +++ b/account/signature_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -45,7 +45,7 @@ func TestBinaryDecode(t *testing.T) { t.Logf("msg: %X, sig: %X", msg, sig) buf, n, err := new(bytes.Buffer), new(int64), new(error) - binary.WriteBinary(sig, buf, n, err) + wire.WriteBinary(sig, buf, n, err) if *err != nil { t.Fatalf("Failed to write Signature: %v", err) } @@ -58,7 +58,7 @@ func TestBinaryDecode(t *testing.T) { t.Fatalf("Unexpected signature type byte") } - sig2, ok := binary.ReadBinary(SignatureEd25519{}, buf, n, err).(SignatureEd25519) + sig2, ok := wire.ReadBinary(SignatureEd25519{}, buf, n, err).(SignatureEd25519) if !ok || *err != nil { t.Fatalf("Failed to read Signature: %v", err) } diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 2c03fc1bd..fba51de27 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -7,7 +7,7 @@ import ( "reflect" "time" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/events" "github.com/tendermint/tendermint/p2p" @@ -271,19 +271,19 @@ const ( type BlockchainMessage interface{} -var _ = binary.RegisterInterface( +var _ = wire.RegisterInterface( struct{ BlockchainMessage }{}, - binary.ConcreteType{&bcBlockRequestMessage{}, msgTypeBlockRequest}, - binary.ConcreteType{&bcBlockResponseMessage{}, msgTypeBlockResponse}, - binary.ConcreteType{&bcStatusResponseMessage{}, msgTypeStatusResponse}, - binary.ConcreteType{&bcStatusRequestMessage{}, msgTypeStatusRequest}, + wire.ConcreteType{&bcBlockRequestMessage{}, msgTypeBlockRequest}, + wire.ConcreteType{&bcBlockResponseMessage{}, msgTypeBlockResponse}, + wire.ConcreteType{&bcStatusResponseMessage{}, msgTypeStatusResponse}, + wire.ConcreteType{&bcStatusRequestMessage{}, msgTypeStatusRequest}, ) func DecodeMessage(bz []byte) (msgType byte, msg BlockchainMessage, err error) { msgType = bz[0] n := new(int64) r := bytes.NewReader(bz) - msg = binary.ReadBinary(struct{ BlockchainMessage }{}, r, n, &err).(struct{ BlockchainMessage }).BlockchainMessage + msg = wire.ReadBinary(struct{ BlockchainMessage }{}, r, n, &err).(struct{ BlockchainMessage }).BlockchainMessage return } diff --git a/blockchain/store.go b/blockchain/store.go index 54e5f475d..e4488a3f5 100644 --- a/blockchain/store.go +++ b/blockchain/store.go @@ -6,7 +6,7 @@ import ( "fmt" "io" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" dbm "github.com/tendermint/tendermint/db" "github.com/tendermint/tendermint/types" @@ -59,7 +59,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block { if r == nil { return nil } - meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta) + meta := wire.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta) if err != nil { PanicCrisis(Fmt("Error reading block meta: %v", err)) } @@ -68,7 +68,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block { part := bs.LoadBlockPart(height, i) bytez = append(bytez, part.Bytes...) } - block := binary.ReadBinary(&types.Block{}, bytes.NewReader(bytez), &n, &err).(*types.Block) + block := wire.ReadBinary(&types.Block{}, bytes.NewReader(bytez), &n, &err).(*types.Block) if err != nil { PanicCrisis(Fmt("Error reading block: %v", err)) } @@ -82,7 +82,7 @@ func (bs *BlockStore) LoadBlockPart(height int, index int) *types.Part { if r == nil { return nil } - part := binary.ReadBinary(&types.Part{}, r, &n, &err).(*types.Part) + part := wire.ReadBinary(&types.Part{}, r, &n, &err).(*types.Part) if err != nil { PanicCrisis(Fmt("Error reading block part: %v", err)) } @@ -96,7 +96,7 @@ func (bs *BlockStore) LoadBlockMeta(height int) *types.BlockMeta { if r == nil { return nil } - meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta) + meta := wire.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta) if err != nil { PanicCrisis(Fmt("Error reading block meta: %v", err)) } @@ -112,7 +112,7 @@ func (bs *BlockStore) LoadBlockValidation(height int) *types.Validation { if r == nil { return nil } - validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation) + validation := wire.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation) if err != nil { PanicCrisis(Fmt("Error reading validation: %v", err)) } @@ -127,7 +127,7 @@ func (bs *BlockStore) LoadSeenValidation(height int) *types.Validation { if r == nil { return nil } - validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation) + validation := wire.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation) if err != nil { PanicCrisis(Fmt("Error reading validation: %v", err)) } @@ -150,7 +150,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s // Save block meta meta := types.NewBlockMeta(block, blockParts) - metaBytes := binary.BinaryBytes(meta) + metaBytes := wire.BinaryBytes(meta) bs.db.Set(calcBlockMetaKey(height), metaBytes) // Save block parts @@ -159,11 +159,11 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s } // Save block validation (duplicate and separate from the Block) - blockValidationBytes := binary.BinaryBytes(block.LastValidation) + blockValidationBytes := wire.BinaryBytes(block.LastValidation) bs.db.Set(calcBlockValidationKey(height-1), blockValidationBytes) // Save seen validation (seen +2/3 precommits for block) - seenValidationBytes := binary.BinaryBytes(seenValidation) + seenValidationBytes := wire.BinaryBytes(seenValidation) bs.db.Set(calcSeenValidationKey(height), seenValidationBytes) // Save new BlockStoreStateJSON descriptor @@ -177,7 +177,7 @@ func (bs *BlockStore) saveBlockPart(height int, index int, part *types.Part) { if height != bs.height+1 { PanicSanity(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height)) } - partBytes := binary.BinaryBytes(part) + partBytes := wire.BinaryBytes(part) bs.db.Set(calcBlockPartKey(height, index), partBytes) } diff --git a/cmd/barak/barak.go b/cmd/barak/barak.go index affe16930..8cffee1f4 100644 --- a/cmd/barak/barak.go +++ b/cmd/barak/barak.go @@ -10,7 +10,7 @@ import ( "sync" "time" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/cmd/barak/types" . "github.com/tendermint/tendermint/common" pcm "github.com/tendermint/tendermint/process" @@ -36,7 +36,7 @@ func ReadBarakOptions(optFile string) *BarakOptions { if err != nil { panic(Fmt("Error reading input: %v", err)) } - opt := binary.ReadJSON(&BarakOptions{}, optBytes, &err).(*BarakOptions) + opt := wire.ReadJSON(&BarakOptions{}, optBytes, &err).(*BarakOptions) if err != nil { panic(Fmt("Error parsing input: %v", err)) } diff --git a/cmd/barak/main.go b/cmd/barak/main.go index c2e64e6ca..2c5e5085e 100644 --- a/cmd/barak/main.go +++ b/cmd/barak/main.go @@ -14,7 +14,7 @@ import ( "reflect" "time" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/cmd/barak/types" . "github.com/tendermint/tendermint/common" cfg "github.com/tendermint/tendermint/config" @@ -108,7 +108,7 @@ func Run(authCommand AuthCommand) (interface{}, error) { func parseValidateCommandStr(authCommandStr string) (Command, error) { var err error - authCommand := binary.ReadJSON(AuthCommand{}, []byte(authCommandStr), &err).(AuthCommand) + authCommand := wire.ReadJSON(AuthCommand{}, []byte(authCommandStr), &err).(AuthCommand) if err != nil { fmt.Printf("Failed to parse auth_command") return nil, errors.New("AuthCommand parse error") @@ -126,7 +126,7 @@ func parseValidateCommand(authCommand AuthCommand) (Command, error) { } // Parse command var err error - command := binary.ReadJSON(NoncedCommand{}, []byte(commandJSONStr), &err).(NoncedCommand) + command := wire.ReadJSON(NoncedCommand{}, []byte(commandJSONStr), &err).(NoncedCommand) if err != nil { fmt.Printf("Failed to parse command") return nil, errors.New("Command parse error") diff --git a/cmd/barak/types/command.go b/cmd/barak/types/command.go index 7a8154dec..a393273d3 100644 --- a/cmd/barak/types/command.go +++ b/cmd/barak/types/command.go @@ -2,7 +2,7 @@ package types import ( acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" ) type AuthCommand struct { @@ -27,16 +27,16 @@ const ( commandTypeQuit = 0x07 ) -// for binary.readReflect -var _ = binary.RegisterInterface( +// for wire.readReflect +var _ = wire.RegisterInterface( struct{ Command }{}, - binary.ConcreteType{CommandStartProcess{}, commandTypeStartProcess}, - binary.ConcreteType{CommandStopProcess{}, commandTypeStopProcess}, - binary.ConcreteType{CommandListProcesses{}, commandTypeListProcesses}, - binary.ConcreteType{CommandServeFile{}, commandTypeServeFile}, - binary.ConcreteType{CommandOpenListener{}, commandTypeOpenListener}, - binary.ConcreteType{CommandCloseListener{}, commandTypeCloseListener}, - binary.ConcreteType{CommandQuit{}, commandTypeQuit}, + wire.ConcreteType{CommandStartProcess{}, commandTypeStartProcess}, + wire.ConcreteType{CommandStopProcess{}, commandTypeStopProcess}, + wire.ConcreteType{CommandListProcesses{}, commandTypeListProcesses}, + wire.ConcreteType{CommandServeFile{}, commandTypeServeFile}, + wire.ConcreteType{CommandOpenListener{}, commandTypeOpenListener}, + wire.ConcreteType{CommandCloseListener{}, commandTypeCloseListener}, + wire.ConcreteType{CommandQuit{}, commandTypeQuit}, ) type CommandStartProcess struct { diff --git a/cmd/barak/validate.go b/cmd/barak/validate.go index 9533fff57..839bc3209 100644 --- a/cmd/barak/validate.go +++ b/cmd/barak/validate.go @@ -43,7 +43,7 @@ func ValidateHandler(handler http.Handler, validators []Validator) http.Handler Path string }{bodyString, pathQuery} // Get sign bytes - signBytes := binary.BinaryBytes(tuple) + signBytes := wire.BinaryBytes(tuple) // Validate the sign bytes. //if validate(signBytes, validators, log.Info("Should sign", "bytes", signBytes) diff --git a/cmd/debora/commands.go b/cmd/debora/commands.go index b29d6d272..84487c2a7 100644 --- a/cmd/debora/commands.go +++ b/cmd/debora/commands.go @@ -7,7 +7,7 @@ import ( "os" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" btypes "github.com/tendermint/tendermint/cmd/barak/types" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/rpc/client" @@ -81,7 +81,7 @@ func DownloadFile(privKey acm.PrivKey, remote string, command btypes.CommandServ CommandJSONStr: string(commandBytes), Signatures: []acm.Signature{signature}, } - authCommandJSONBytes := binary.JSONBytes(authCommand) + authCommandJSONBytes := wire.JSONBytes(authCommand) // Make request and write to outPath. httpResponse, err := http.PostForm(remote+"/download", url.Values{"auth_command": {string(authCommandJSONBytes)}}) if err != nil { @@ -133,7 +133,7 @@ func SignCommand(privKey acm.PrivKey, nonce int64, command btypes.Command) ([]by Nonce: nonce, Command: command, } - commandJSONBytes := binary.JSONBytes(noncedCommand) + commandJSONBytes := wire.JSONBytes(noncedCommand) signature := privKey.Sign(commandJSONBytes) return commandJSONBytes, signature } diff --git a/cmd/debora/main.go b/cmd/debora/main.go index 66e19a0f6..ce4984586 100644 --- a/cmd/debora/main.go +++ b/cmd/debora/main.go @@ -11,7 +11,7 @@ import ( "sync" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" btypes "github.com/tendermint/tendermint/cmd/barak/types" . "github.com/tendermint/tendermint/common" cfg "github.com/tendermint/tendermint/config" @@ -133,7 +133,7 @@ func ReadConfig(configFilePath string) { if err != nil { Exit(Fmt("Failed to read config file %v. %v\n", configFilePath, err)) } - binary.ReadJSON(&Config, configJSONBytes, &err) + wire.ReadJSON(&Config, configJSONBytes, &err) if err != nil { Exit(Fmt("Failed to parse config. %v", err)) } diff --git a/cmd/tendermint/gen_account.go b/cmd/tendermint/gen_account.go index a8780ae7d..2f9a4811d 100644 --- a/cmd/tendermint/gen_account.go +++ b/cmd/tendermint/gen_account.go @@ -4,12 +4,12 @@ import ( "fmt" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" ) func gen_account() { privAccount := acm.GenPrivAccount() - privAccountJSONBytes := binary.JSONBytes(privAccount) + privAccountJSONBytes := wire.JSONBytes(privAccount) fmt.Printf(`Generated a new account! %v diff --git a/cmd/tendermint/gen_tx.go b/cmd/tendermint/gen_tx.go index 39b859bed..50d200b6f 100644 --- a/cmd/tendermint/gen_tx.go +++ b/cmd/tendermint/gen_tx.go @@ -9,7 +9,7 @@ import ( "strconv" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" dbm "github.com/tendermint/tendermint/db" sm "github.com/tendermint/tendermint/state" @@ -54,7 +54,7 @@ func gen_tx() { // Get source pubkey srcPubKeyBytes := getByteSliceFromHex("Enter source pubkey: ") r, n, err := bytes.NewReader(srcPubKeyBytes), new(int64), new(error) - srcPubKey := binary.ReadBinary(struct{ acm.PubKey }{}, r, n, err).(struct{ acm.PubKey }).PubKey + srcPubKey := wire.ReadBinary(struct{ acm.PubKey }{}, r, n, err).(struct{ acm.PubKey }).PubKey if *err != nil { Exit(Fmt("Invalid PubKey. Error: %v", err)) } @@ -103,17 +103,17 @@ func gen_tx() { } // Show the intermediate form. - fmt.Printf("Generated tx: %X\n", binary.BinaryBytes(tx)) + fmt.Printf("Generated tx: %X\n", wire.BinaryBytes(tx)) // Get source privkey (for signing) srcPrivKeyBytes := getByteSliceFromHex("Enter source privkey (for signing): ") r, n, err = bytes.NewReader(srcPrivKeyBytes), new(int64), new(error) - srcPrivKey := binary.ReadBinary(struct{ acm.PrivKey }{}, r, n, err).(struct{ acm.PrivKey }).PrivKey + srcPrivKey := wire.ReadBinary(struct{ acm.PrivKey }{}, r, n, err).(struct{ acm.PrivKey }).PrivKey if *err != nil { Exit(Fmt("Invalid PrivKey. Error: %v", err)) } // Sign tx.Inputs[0].Signature = srcPrivKey.Sign(acm.SignBytes(config.GetString("chain_id"), tx)) - fmt.Printf("Signed tx: %X\n", binary.BinaryBytes(tx)) + fmt.Printf("Signed tx: %X\n", wire.BinaryBytes(tx)) } diff --git a/cmd/tendermint/gen_validator.go b/cmd/tendermint/gen_validator.go index 019876fc8..e71795b6f 100644 --- a/cmd/tendermint/gen_validator.go +++ b/cmd/tendermint/gen_validator.go @@ -3,14 +3,14 @@ package main import ( "fmt" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" sm "github.com/tendermint/tendermint/state" ) func gen_validator() { privValidator := sm.GenPrivValidator() - privValidatorJSONBytes := binary.JSONBytes(privValidator) + privValidatorJSONBytes := wire.JSONBytes(privValidator) fmt.Printf(`Generated a new validator! Paste the following JSON into your %v file diff --git a/consensus/reactor.go b/consensus/reactor.go index 1068edd45..1778f7d56 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -8,7 +8,7 @@ import ( "sync" "time" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" bc "github.com/tendermint/tendermint/blockchain" . "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/consensus/types" @@ -909,15 +909,15 @@ const ( type ConsensusMessage interface{} -var _ = binary.RegisterInterface( +var _ = wire.RegisterInterface( struct{ ConsensusMessage }{}, - binary.ConcreteType{&NewRoundStepMessage{}, msgTypeNewRoundStep}, - binary.ConcreteType{&CommitStepMessage{}, msgTypeCommitStep}, - binary.ConcreteType{&ProposalMessage{}, msgTypeProposal}, - binary.ConcreteType{&ProposalPOLMessage{}, msgTypeProposalPOL}, - binary.ConcreteType{&BlockPartMessage{}, msgTypeBlockPart}, - binary.ConcreteType{&VoteMessage{}, msgTypeVote}, - binary.ConcreteType{&HasVoteMessage{}, msgTypeHasVote}, + wire.ConcreteType{&NewRoundStepMessage{}, msgTypeNewRoundStep}, + wire.ConcreteType{&CommitStepMessage{}, msgTypeCommitStep}, + wire.ConcreteType{&ProposalMessage{}, msgTypeProposal}, + wire.ConcreteType{&ProposalPOLMessage{}, msgTypeProposalPOL}, + wire.ConcreteType{&BlockPartMessage{}, msgTypeBlockPart}, + wire.ConcreteType{&VoteMessage{}, msgTypeVote}, + wire.ConcreteType{&HasVoteMessage{}, msgTypeHasVote}, ) // TODO: check for unnecessary extra bytes at the end. @@ -925,7 +925,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error) { msgType = bz[0] n := new(int64) r := bytes.NewReader(bz) - msg = binary.ReadBinary(struct{ ConsensusMessage }{}, r, n, &err).(struct{ ConsensusMessage }).ConsensusMessage + msg = wire.ReadBinary(struct{ ConsensusMessage }{}, r, n, &err).(struct{ ConsensusMessage }).ConsensusMessage return } diff --git a/consensus/state.go b/consensus/state.go index 0f24fe3e0..abea5b2d0 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -158,7 +158,7 @@ import ( "time" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" bc "github.com/tendermint/tendermint/blockchain" . "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/consensus/types" @@ -1028,7 +1028,7 @@ func (cs *ConsensusState) AddProposalBlockPart(height int, part *types.Part) (ad // Added and completed! var n int64 var err error - cs.ProposalBlock = binary.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(), &n, &err).(*types.Block) + cs.ProposalBlock = wire.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(), &n, &err).(*types.Block) log.Info("Received complete proposal", "hash", cs.ProposalBlock.Hash()) if cs.Step == RoundStepPropose && cs.isProposalComplete() { // Move onto the next step diff --git a/consensus/types/proposal.go b/consensus/types/proposal.go index a1999f20d..54f54f13d 100644 --- a/consensus/types/proposal.go +++ b/consensus/types/proposal.go @@ -6,7 +6,7 @@ import ( "io" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/types" ) @@ -39,9 +39,9 @@ func (p *Proposal) String() string { } func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) - binary.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) + wire.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err) p.BlockPartsHeader.WriteSignBytes(w, n, err) - binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_round":%v`, p.Height, p.POLRound)), w, n, err) - binary.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err) + wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_round":%v`, p.Height, p.POLRound)), w, n, err) + wire.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err) } diff --git a/consensus/vote_set.go b/consensus/vote_set.go index e2fec51b5..643cb32e8 100644 --- a/consensus/vote_set.go +++ b/consensus/vote_set.go @@ -7,7 +7,7 @@ import ( "sync" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" @@ -151,7 +151,7 @@ func (voteSet *VoteSet) addVote(val *sm.Validator, valIndex int, vote *types.Vot // Add vote. voteSet.votes[valIndex] = vote voteSet.votesBitArray.SetIndex(valIndex, true) - blockKey := string(vote.BlockHash) + string(binary.BinaryBytes(vote.BlockParts)) + blockKey := string(vote.BlockHash) + string(wire.BinaryBytes(vote.BlockParts)) totalBlockHashVotes := voteSet.votesByBlock[blockKey] + val.VotingPower voteSet.votesByBlock[blockKey] = totalBlockHashVotes voteSet.totalVotes += val.VotingPower diff --git a/crawler/crawl.go b/crawler/crawl.go index 90642b85c..0a4058154 100644 --- a/crawler/crawl.go +++ b/crawler/crawl.go @@ -2,7 +2,7 @@ package crawler import ( "fmt" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpcclient "github.com/tendermint/tendermint/rpc/core_client" "github.com/tendermint/tendermint/types" @@ -196,7 +196,7 @@ func (c *Crawler) consumeMessage(wsMsg *rpcclient.WSMsg, node *Node) error { Error string } var err error - binary.ReadJSON(&response, wsMsg.Data, &err) + wire.ReadJSON(&response, wsMsg.Data, &err) if err != nil { return err } diff --git a/mempool/reactor.go b/mempool/reactor.go index 3e930985f..2633648ca 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -5,7 +5,7 @@ import ( "fmt" "reflect" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/events" "github.com/tendermint/tendermint/p2p" @@ -114,16 +114,16 @@ const ( type MempoolMessage interface{} -var _ = binary.RegisterInterface( +var _ = wire.RegisterInterface( struct{ MempoolMessage }{}, - binary.ConcreteType{&TxMessage{}, msgTypeTx}, + wire.ConcreteType{&TxMessage{}, msgTypeTx}, ) func DecodeMessage(bz []byte) (msgType byte, msg MempoolMessage, err error) { msgType = bz[0] n := new(int64) r := bytes.NewReader(bz) - msg = binary.ReadBinary(struct{ MempoolMessage }{}, r, n, &err).(struct{ MempoolMessage }).MempoolMessage + msg = wire.ReadBinary(struct{ MempoolMessage }{}, r, n, &err).(struct{ MempoolMessage }).MempoolMessage return } diff --git a/merkle/iavl_node.go b/merkle/iavl_node.go index 4fc04ef28..faf86890f 100644 --- a/merkle/iavl_node.go +++ b/merkle/iavl_node.go @@ -5,7 +5,7 @@ import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160" "io" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -39,8 +39,8 @@ func ReadIAVLNode(t *IAVLTree, r io.Reader, n *int64, err *error) *IAVLNode { node := &IAVLNode{} // node header - node.height = binary.ReadInt8(r, n, err) - node.size = binary.ReadVarint(r, n, err) + node.height = wire.ReadInt8(r, n, err) + node.size = wire.ReadVarint(r, n, err) node.key = decodeByteSlice(t.keyCodec, r, n, err) if node.height == 0 { @@ -48,8 +48,8 @@ func ReadIAVLNode(t *IAVLTree, r io.Reader, n *int64, err *error) *IAVLNode { node.value = decodeByteSlice(t.valueCodec, r, n, err) } else { // children - node.leftHash = binary.ReadByteSlice(r, n, err) - node.rightHash = binary.ReadByteSlice(r, n, err) + node.leftHash = wire.ReadByteSlice(r, n, err) + node.rightHash = wire.ReadByteSlice(r, n, err) } return node } @@ -148,8 +148,8 @@ func (node *IAVLNode) hashWithCount(t *IAVLTree) ([]byte, int) { // NOTE: sets hashes recursively func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCount int, err error) { // height & size - binary.WriteInt8(node.height, w, &n, &err) - binary.WriteVarint(node.size, w, &n, &err) + wire.WriteInt8(node.height, w, &n, &err) + wire.WriteVarint(node.size, w, &n, &err) // key is not written for inner nodes, unlike writePersistBytes if node.height == 0 { @@ -166,7 +166,7 @@ func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCou if node.leftHash == nil { PanicSanity("node.leftHash was nil in writeHashBytes") } - binary.WriteByteSlice(node.leftHash, w, &n, &err) + wire.WriteByteSlice(node.leftHash, w, &n, &err) // right if node.rightNode != nil { rightHash, rightCount := node.rightNode.hashWithCount(t) @@ -176,7 +176,7 @@ func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCou if node.rightHash == nil { PanicSanity("node.rightHash was nil in writeHashBytes") } - binary.WriteByteSlice(node.rightHash, w, &n, &err) + wire.WriteByteSlice(node.rightHash, w, &n, &err) } return } @@ -209,8 +209,8 @@ func (node *IAVLNode) save(t *IAVLTree) []byte { // NOTE: sets hashes recursively func (node *IAVLNode) writePersistBytes(t *IAVLTree, w io.Writer) (n int64, err error) { // node header - binary.WriteInt8(node.height, w, &n, &err) - binary.WriteVarint(node.size, w, &n, &err) + wire.WriteInt8(node.height, w, &n, &err) + wire.WriteVarint(node.size, w, &n, &err) // key (unlike writeHashBytes, key is written for inner nodes) encodeByteSlice(node.key, t.keyCodec, w, &n, &err) @@ -222,12 +222,12 @@ func (node *IAVLNode) writePersistBytes(t *IAVLTree, w io.Writer) (n int64, err if node.leftHash == nil { PanicSanity("node.leftHash was nil in writePersistBytes") } - binary.WriteByteSlice(node.leftHash, w, &n, &err) + wire.WriteByteSlice(node.leftHash, w, &n, &err) // right if node.rightHash == nil { PanicSanity("node.rightHash was nil in writePersistBytes") } - binary.WriteByteSlice(node.rightHash, w, &n, &err) + wire.WriteByteSlice(node.rightHash, w, &n, &err) } return } @@ -439,8 +439,8 @@ func (node *IAVLNode) rmd(t *IAVLTree) *IAVLNode { //-------------------------------------------------------------------------------- // Read a (length prefixed) byteslice then decode the object using the codec -func decodeByteSlice(codec binary.Codec, r io.Reader, n *int64, err *error) interface{} { - bytez := binary.ReadByteSlice(r, n, err) +func decodeByteSlice(codec wire.Codec, r io.Reader, n *int64, err *error) interface{} { + bytez := wire.ReadByteSlice(r, n, err) if *err != nil { return nil } @@ -449,11 +449,11 @@ func decodeByteSlice(codec binary.Codec, r io.Reader, n *int64, err *error) inte } // Encode object using codec, then write a (length prefixed) byteslice. -func encodeByteSlice(o interface{}, codec binary.Codec, w io.Writer, n *int64, err *error) { +func encodeByteSlice(o interface{}, codec wire.Codec, w io.Writer, n *int64, err *error) { buf, n_ := new(bytes.Buffer), new(int64) codec.Encode(o, buf, n_, err) if *err != nil { return } - binary.WriteByteSlice(buf.Bytes(), w, n, err) + wire.WriteByteSlice(buf.Bytes(), w, n, err) } diff --git a/merkle/iavl_proof.go b/merkle/iavl_proof.go index 58d8468b3..2f4f7763d 100644 --- a/merkle/iavl_proof.go +++ b/merkle/iavl_proof.go @@ -5,7 +5,7 @@ import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -46,14 +46,14 @@ func (branch IAVLProofInnerNode) Hash(childHash []byte) []byte { hasher := ripemd160.New() buf := new(bytes.Buffer) n, err := int64(0), error(nil) - binary.WriteInt8(branch.Height, buf, &n, &err) - binary.WriteVarint(branch.Size, buf, &n, &err) + wire.WriteInt8(branch.Height, buf, &n, &err) + wire.WriteVarint(branch.Size, buf, &n, &err) if len(branch.Left) == 0 { - binary.WriteByteSlice(childHash, buf, &n, &err) - binary.WriteByteSlice(branch.Right, buf, &n, &err) + wire.WriteByteSlice(childHash, buf, &n, &err) + wire.WriteByteSlice(branch.Right, buf, &n, &err) } else { - binary.WriteByteSlice(branch.Left, buf, &n, &err) - binary.WriteByteSlice(childHash, buf, &n, &err) + wire.WriteByteSlice(branch.Left, buf, &n, &err) + wire.WriteByteSlice(childHash, buf, &n, &err) } if err != nil { PanicCrisis(Fmt("Failed to hash IAVLProofInnerNode: %v", err)) @@ -72,10 +72,10 @@ func (leaf IAVLProofLeafNode) Hash() []byte { hasher := ripemd160.New() buf := new(bytes.Buffer) n, err := int64(0), error(nil) - binary.WriteInt8(0, buf, &n, &err) - binary.WriteVarint(1, buf, &n, &err) - binary.WriteByteSlice(leaf.KeyBytes, buf, &n, &err) - binary.WriteByteSlice(leaf.ValueBytes, buf, &n, &err) + wire.WriteInt8(0, buf, &n, &err) + wire.WriteVarint(1, buf, &n, &err) + wire.WriteByteSlice(leaf.KeyBytes, buf, &n, &err) + wire.WriteByteSlice(leaf.ValueBytes, buf, &n, &err) if err != nil { PanicCrisis(Fmt("Failed to hash IAVLProofLeafNode: %v", err)) } diff --git a/merkle/iavl_test.go b/merkle/iavl_test.go index b0f5d9bf9..889f8e1b3 100644 --- a/merkle/iavl_test.go +++ b/merkle/iavl_test.go @@ -4,7 +4,7 @@ import ( "bytes" "fmt" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common/test" "github.com/tendermint/tendermint/db" @@ -43,7 +43,7 @@ func N(l, r interface{}) *IAVLNode { // Setup a deep node func T(n *IAVLNode) *IAVLTree { - t := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, nil) + t := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, nil) n.hashWithCount(t) t.root = n return t @@ -149,7 +149,7 @@ func TestIntegration(t *testing.T) { } records := make([]*record, 400) - var tree *IAVLTree = NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, nil) + var tree *IAVLTree = NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, nil) randomRecord := func() *record { return &record{randstr(20), randstr(20)} @@ -219,7 +219,7 @@ func TestPersistence(t *testing.T) { } // Construct some tree and save it - t1 := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, db) + t1 := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, db) for key, value := range records { t1.Set(key, value) } @@ -228,7 +228,7 @@ func TestPersistence(t *testing.T) { hash, _ := t1.HashWithCount() // Load a tree - t2 := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, db) + t2 := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, db) t2.Load(hash) for key, value := range records { _, t2value := t2.Get(key) @@ -245,15 +245,15 @@ func testProof(t *testing.T, proof *IAVLProof, keyBytes, valueBytes, rootHash [] return } // Write/Read then verify. - proofBytes := binary.BinaryBytes(proof) + proofBytes := wire.BinaryBytes(proof) n, err := int64(0), error(nil) - proof2 := binary.ReadBinary(&IAVLProof{}, bytes.NewBuffer(proofBytes), &n, &err).(*IAVLProof) + proof2 := wire.ReadBinary(&IAVLProof{}, bytes.NewBuffer(proofBytes), &n, &err).(*IAVLProof) if err != nil { t.Errorf("Failed to read IAVLProof from bytes: %v", err) return } if !proof2.Verify(keyBytes, valueBytes, rootHash) { - // t.Log(Fmt("%X\n%X\n", proofBytes, binary.BinaryBytes(proof2))) + // t.Log(Fmt("%X\n%X\n", proofBytes, wire.BinaryBytes(proof2))) t.Errorf("Invalid proof after write/read. Verification failed.") return } @@ -261,7 +261,7 @@ func testProof(t *testing.T, proof *IAVLProof, keyBytes, valueBytes, rootHash [] for i := 0; i < 5; i++ { badProofBytes := MutateByteSlice(proofBytes) n, err := int64(0), error(nil) - badProof := binary.ReadBinary(&IAVLProof{}, bytes.NewBuffer(badProofBytes), &n, &err).(*IAVLProof) + badProof := wire.ReadBinary(&IAVLProof{}, bytes.NewBuffer(badProofBytes), &n, &err).(*IAVLProof) if err != nil { continue // This is fine. } @@ -273,10 +273,10 @@ func testProof(t *testing.T, proof *IAVLProof, keyBytes, valueBytes, rootHash [] func TestIAVLProof(t *testing.T) { - // Convenient wrapper around binary.BasicCodec. + // Convenient wrapper around wire.BasicCodec. toBytes := func(o interface{}) []byte { buf, n, err := new(bytes.Buffer), int64(0), error(nil) - binary.BasicCodec.Encode(o, buf, &n, &err) + wire.BasicCodec.Encode(o, buf, &n, &err) if err != nil { panic(Fmt("Failed to encode thing: %v", err)) } @@ -285,7 +285,7 @@ func TestIAVLProof(t *testing.T) { // Construct some random tree db := db.NewMemDB() - var tree *IAVLTree = NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 100, db) + var tree *IAVLTree = NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 100, db) for i := 0; i < 1000; i++ { key, value := randstr(20), randstr(20) tree.Set(key, value) @@ -315,7 +315,7 @@ func TestIAVLProof(t *testing.T) { func BenchmarkImmutableAvlTree(b *testing.B) { b.StopTimer() - t := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, nil) + t := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, nil) // 23000ns/op, 43000ops/s // for i := 0; i < 10000000; i++ { for i := 0; i < 1000000; i++ { diff --git a/merkle/iavl_tree.go b/merkle/iavl_tree.go index 19f9c6cdf..9ea022956 100644 --- a/merkle/iavl_tree.go +++ b/merkle/iavl_tree.go @@ -5,7 +5,7 @@ import ( "container/list" "sync" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" dbm "github.com/tendermint/tendermint/db" ) @@ -15,13 +15,13 @@ Immutable AVL Tree (wraps the Node root) This tree is not goroutine safe. */ type IAVLTree struct { - keyCodec binary.Codec - valueCodec binary.Codec + keyCodec wire.Codec + valueCodec wire.Codec root *IAVLNode ndb *nodeDB } -func NewIAVLTree(keyCodec, valueCodec binary.Codec, cacheSize int, db dbm.DB) *IAVLTree { +func NewIAVLTree(keyCodec, valueCodec wire.Codec, cacheSize int, db dbm.DB) *IAVLTree { if db == nil { // In-memory IAVLTree return &IAVLTree{ diff --git a/merkle/simple_tree.go b/merkle/simple_tree.go index 42a7de6c2..af642a682 100644 --- a/merkle/simple_tree.go +++ b/merkle/simple_tree.go @@ -30,7 +30,7 @@ import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -38,8 +38,8 @@ func SimpleHashFromTwoHashes(left []byte, right []byte) []byte { var n int64 var err error var hasher = ripemd160.New() - binary.WriteByteSlice(left, hasher, &n, &err) - binary.WriteByteSlice(right, hasher, &n, &err) + wire.WriteByteSlice(left, hasher, &n, &err) + wire.WriteByteSlice(right, hasher, &n, &err) if err != nil { PanicCrisis(err) } @@ -72,7 +72,7 @@ func SimpleHashFromBinaries(items []interface{}) []byte { // General Convenience func SimpleHashFromBinary(item interface{}) []byte { hasher, n, err := ripemd160.New(), new(int64), new(error) - binary.WriteBinary(item, hasher, n, err) + wire.WriteBinary(item, hasher, n, err) if *err != nil { PanicCrisis(err) } diff --git a/node/node.go b/node/node.go index 08b9d249c..39b6e378f 100644 --- a/node/node.go +++ b/node/node.go @@ -11,7 +11,7 @@ import ( "time" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" bc "github.com/tendermint/tendermint/blockchain" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/consensus" @@ -56,7 +56,7 @@ func NewNode() *Node { state.Save() // write the gendoc to db buf, n, err := new(bytes.Buffer), new(int64), new(error) - binary.WriteJSON(genDoc, buf, n, err) + wire.WriteJSON(genDoc, buf, n, err) stateDB.Set(sm.GenDocKey, buf.Bytes()) if *err != nil { log.Error("Unable to write gendoc to db", "error", err) @@ -65,7 +65,7 @@ func NewNode() *Node { } else { genDocBytes := stateDB.Get(sm.GenDocKey) err := new(error) - binary.ReadJSONPtr(&genDoc, genDocBytes, err) + wire.ReadJSONPtr(&genDoc, genDocBytes, err) if *err != nil { log.Error("Unable to read gendoc from db", "error", err) os.Exit(1) diff --git a/p2p/README.md b/p2p/README.md index cfbbf5c7d..a7324b714 100644 --- a/p2p/README.md +++ b/p2p/README.md @@ -22,7 +22,7 @@ func (m MConnection) TrySend(chId byte, msg interface{}) bool {} `Send(chId, msg)` is a blocking call that waits until `msg` is successfully queued for the channel with the given id byte `chId`. The message `msg` is serialized -using the `tendermint/binary` submodule's `WriteBinary()` reflection routine. +using the `tendermint/wire` submodule's `WriteBinary()` reflection routine. `TrySend(chId, msg)` is a nonblocking call that returns false if the channel's queue is full. diff --git a/p2p/connection.go b/p2p/connection.go index 1c0bfd6d5..6d3591de3 100644 --- a/p2p/connection.go +++ b/p2p/connection.go @@ -11,7 +11,7 @@ import ( "time" flow "github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/mxk/go1/flowcontrol" - "github.com/tendermint/tendermint/binary" //"github.com/tendermint/log15" + "github.com/tendermint/tendermint/wire" //"github.com/tendermint/log15" . "github.com/tendermint/tendermint/common" ) @@ -50,7 +50,7 @@ There are two methods for sending messages: `Send(chId, msg)` is a blocking call that waits until `msg` is successfully queued for the channel with the given id byte `chId`, or until the request times out. -The message `msg` is serialized using the `tendermint/binary` submodule's +The message `msg` is serialized using the `tendermint/wire` submodule's `WriteBinary()` reflection routine. `TrySend(chId, msg)` is a nonblocking call that returns false if the channel's @@ -189,7 +189,7 @@ func (c *MConnection) Send(chId byte, msg interface{}) bool { return false } - log.Info("Send", "channel", chId, "conn", c, "msg", msg) //, "bytes", binary.BinaryBytes(msg)) + log.Info("Send", "channel", chId, "conn", c, "msg", msg) //, "bytes", wire.BinaryBytes(msg)) // Send message to channel. channel, ok := c.channelsIdx[chId] @@ -198,7 +198,7 @@ func (c *MConnection) Send(chId byte, msg interface{}) bool { return false } - success := channel.sendBytes(binary.BinaryBytes(msg)) + success := channel.sendBytes(wire.BinaryBytes(msg)) if success { // Wake up sendRoutine if necessary select { @@ -227,7 +227,7 @@ func (c *MConnection) TrySend(chId byte, msg interface{}) bool { return false } - ok = channel.trySendBytes(binary.BinaryBytes(msg)) + ok = channel.trySendBytes(wire.BinaryBytes(msg)) if ok { // Wake up sendRoutine if necessary select { @@ -271,12 +271,12 @@ FOR_LOOP: } case <-c.pingTimer.Ch: log.Info("Send Ping") - binary.WriteByte(packetTypePing, c.bufWriter, &n, &err) + wire.WriteByte(packetTypePing, c.bufWriter, &n, &err) c.sendMonitor.Update(int(n)) c.flush() case <-c.pong: log.Info("Send Pong") - binary.WriteByte(packetTypePong, c.bufWriter, &n, &err) + wire.WriteByte(packetTypePong, c.bufWriter, &n, &err) c.sendMonitor.Update(int(n)) c.flush() case <-c.quit: @@ -390,7 +390,7 @@ FOR_LOOP: // Read packet type var n int64 var err error - pktType := binary.ReadByte(c.bufReader, &n, &err) + pktType := wire.ReadByte(c.bufReader, &n, &err) c.recvMonitor.Update(int(n)) if err != nil { if c.IsRunning() { @@ -411,7 +411,7 @@ FOR_LOOP: log.Info("Receive Pong") case packetTypeMsg: pkt, n, err := msgPacket{}, int64(0), error(nil) - binary.ReadBinaryPtr(&pkt, c.bufReader, &n, &err) + wire.ReadBinaryPtr(&pkt, c.bufReader, &n, &err) c.recvMonitor.Update(int(n)) if err != nil { if c.IsRunning() { @@ -573,8 +573,8 @@ func (ch *Channel) nextMsgPacket() msgPacket { func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int64, err error) { packet := ch.nextMsgPacket() log.Debug("Write Msg Packet", "conn", ch.conn, "packet", packet) - binary.WriteByte(packetTypeMsg, w, &n, &err) - binary.WriteBinary(packet, w, &n, &err) + wire.WriteByte(packetTypeMsg, w, &n, &err) + wire.WriteBinary(packet, w, &n, &err) if err != nil { ch.recentlySent += n } @@ -585,8 +585,8 @@ func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int64, err error) { // Not goroutine-safe func (ch *Channel) recvMsgPacket(packet msgPacket) ([]byte, error) { log.Debug("Read Msg Packet", "conn", ch.conn, "packet", packet) - if binary.MaxBinaryReadSize < len(ch.recving)+len(packet.Bytes) { - return nil, binary.ErrBinaryReadSizeOverflow + if wire.MaxBinaryReadSize < len(ch.recving)+len(packet.Bytes) { + return nil, wire.ErrBinaryReadSizeOverflow } ch.recving = append(ch.recving, packet.Bytes...) if packet.EOF == byte(0x01) { diff --git a/p2p/peer.go b/p2p/peer.go index 48ab7343e..c1f12db5d 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -5,7 +5,7 @@ import ( "io" "net" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/types" ) @@ -30,11 +30,11 @@ func peerHandshake(conn net.Conn, ourNodeInfo *types.NodeInfo) (*types.NodeInfo, Parallel( func() { var n int64 - binary.WriteBinary(ourNodeInfo, conn, &n, &err1) + wire.WriteBinary(ourNodeInfo, conn, &n, &err1) }, func() { var n int64 - binary.ReadBinary(peerNodeInfo, conn, &n, &err2) + wire.ReadBinary(peerNodeInfo, conn, &n, &err2) log.Notice("Peer handshake", "peerNodeInfo", peerNodeInfo) }) if err1 != nil { @@ -112,7 +112,7 @@ func (p *Peer) CanSend(chId byte) bool { } func (p *Peer) WriteTo(w io.Writer) (n int64, err error) { - binary.WriteString(p.Key, w, &n, &err) + wire.WriteString(p.Key, w, &n, &err) return } diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index 6e7ee5430..0f298d9b9 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -8,7 +8,7 @@ import ( "reflect" "time" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/events" ) @@ -225,17 +225,17 @@ const ( type PexMessage interface{} -var _ = binary.RegisterInterface( +var _ = wire.RegisterInterface( struct{ PexMessage }{}, - binary.ConcreteType{&pexRequestMessage{}, msgTypeRequest}, - binary.ConcreteType{&pexAddrsMessage{}, msgTypeAddrs}, + wire.ConcreteType{&pexRequestMessage{}, msgTypeRequest}, + wire.ConcreteType{&pexAddrsMessage{}, msgTypeAddrs}, ) func DecodeMessage(bz []byte) (msgType byte, msg PexMessage, err error) { msgType = bz[0] n := new(int64) r := bytes.NewReader(bz) - msg = binary.ReadBinary(struct{ PexMessage }{}, r, n, &err).(struct{ PexMessage }).PexMessage + msg = wire.ReadBinary(struct{ PexMessage }{}, r, n, &err).(struct{ PexMessage }).PexMessage return } diff --git a/p2p/secret_connection.go b/p2p/secret_connection.go index 1311d42d1..a8360ac9f 100644 --- a/p2p/secret_connection.go +++ b/p2p/secret_connection.go @@ -21,8 +21,8 @@ import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160" acm "github.com/tendermint/tendermint/account" - bm "github.com/tendermint/tendermint/binary" . "github.com/tendermint/tendermint/common" + "github.com/tendermint/tendermint/wire" ) // 2 + 1024 == 1026 total frame size @@ -270,7 +270,7 @@ func shareAuthSignature(sc *SecretConnection, pubKey acm.PubKeyEd25519, signatur Parallel( func() { - msgBytes := bm.BinaryBytes(authSigMessage{pubKey, signature}) + msgBytes := wire.BinaryBytes(authSigMessage{pubKey, signature}) _, err1 = sc.Write(msgBytes) }, func() { @@ -280,7 +280,7 @@ func shareAuthSignature(sc *SecretConnection, pubKey acm.PubKeyEd25519, signatur return } n := int64(0) // not used. - recvMsg = bm.ReadBinary(authSigMessage{}, bytes.NewBuffer(readBuffer), &n, &err2).(authSigMessage) + recvMsg = wire.ReadBinary(authSigMessage{}, bytes.NewBuffer(readBuffer), &n, &err2).(authSigMessage) }) if err1 != nil { diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 571a2691d..688391358 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -7,7 +7,7 @@ import ( "time" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/types" ) @@ -164,8 +164,8 @@ func TestSwitches(t *testing.T) { if len(ch0Msgs) != 1 { t.Errorf("Expected to have received 1 message in ch0") } - if !bytes.Equal(ch0Msgs[0].Bytes, binary.BinaryBytes(ch0Msg)) { - t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", binary.BinaryBytes(ch0Msg), ch0Msgs[0].Bytes) + if !bytes.Equal(ch0Msgs[0].Bytes, wire.BinaryBytes(ch0Msg)) { + t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", wire.BinaryBytes(ch0Msg), ch0Msgs[0].Bytes) } // Check message on ch1 @@ -173,8 +173,8 @@ func TestSwitches(t *testing.T) { if len(ch1Msgs) != 1 { t.Errorf("Expected to have received 1 message in ch1") } - if !bytes.Equal(ch1Msgs[0].Bytes, binary.BinaryBytes(ch1Msg)) { - t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", binary.BinaryBytes(ch1Msg), ch1Msgs[0].Bytes) + if !bytes.Equal(ch1Msgs[0].Bytes, wire.BinaryBytes(ch1Msg)) { + t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", wire.BinaryBytes(ch1Msg), ch1Msgs[0].Bytes) } // Check message on ch2 @@ -182,8 +182,8 @@ func TestSwitches(t *testing.T) { if len(ch2Msgs) != 1 { t.Errorf("Expected to have received 1 message in ch2") } - if !bytes.Equal(ch2Msgs[0].Bytes, binary.BinaryBytes(ch2Msg)) { - t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", binary.BinaryBytes(ch2Msg), ch2Msgs[0].Bytes) + if !bytes.Equal(ch2Msgs[0].Bytes, wire.BinaryBytes(ch2Msg)) { + t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", wire.BinaryBytes(ch2Msg), ch2Msgs[0].Bytes) } } diff --git a/permission/types/snatives.go b/permission/types/snatives.go index 5057bd42d..3fad9bd8f 100644 --- a/permission/types/snatives.go +++ b/permission/types/snatives.go @@ -1,7 +1,7 @@ package types import ( - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" ) //--------------------------------------------------------------------------------------------------- @@ -25,16 +25,16 @@ const ( PermArgsTypeRmRole = byte(0x07) ) -// for binary.readReflect -var _ = binary.RegisterInterface( +// for wire.readReflect +var _ = wire.RegisterInterface( struct{ PermArgs }{}, - binary.ConcreteType{&HasBaseArgs{}, PermArgsTypeHasBase}, - binary.ConcreteType{&SetBaseArgs{}, PermArgsTypeSetBase}, - binary.ConcreteType{&UnsetBaseArgs{}, PermArgsTypeUnsetBase}, - binary.ConcreteType{&SetGlobalArgs{}, PermArgsTypeSetGlobal}, - binary.ConcreteType{&HasRoleArgs{}, PermArgsTypeHasRole}, - binary.ConcreteType{&AddRoleArgs{}, PermArgsTypeAddRole}, - binary.ConcreteType{&RmRoleArgs{}, PermArgsTypeRmRole}, + wire.ConcreteType{&HasBaseArgs{}, PermArgsTypeHasBase}, + wire.ConcreteType{&SetBaseArgs{}, PermArgsTypeSetBase}, + wire.ConcreteType{&UnsetBaseArgs{}, PermArgsTypeUnsetBase}, + wire.ConcreteType{&SetGlobalArgs{}, PermArgsTypeSetGlobal}, + wire.ConcreteType{&HasRoleArgs{}, PermArgsTypeHasRole}, + wire.ConcreteType{&AddRoleArgs{}, PermArgsTypeAddRole}, + wire.ConcreteType{&RmRoleArgs{}, PermArgsTypeRmRole}, ) type HasBaseArgs struct { diff --git a/rpc/client/client.go b/rpc/client/client.go index 95abec98c..5fec2530e 100644 --- a/rpc/client/client.go +++ b/rpc/client/client.go @@ -7,7 +7,7 @@ import ( "io/ioutil" "net/http" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/rpc/types" ) @@ -20,7 +20,7 @@ func Call(remote string, method string, params []interface{}, dest interface{}) Params: params, Id: "", } - requestBytes := binary.JSONBytes(request) + requestBytes := wire.JSONBytes(request) requestBuf := bytes.NewBuffer(requestBytes) log.Info(Fmt("RPC request to %v: %v", remote, string(requestBytes))) httpResponse, err := http.Post(remote, "text/json", requestBuf) @@ -46,6 +46,6 @@ func Call(remote string, method string, params []interface{}, dest interface{}) if errorStr != "" { return dest, errors.New(errorStr) } - dest = binary.ReadJSONObject(dest, resultJSONObject, &err) + dest = wire.ReadJSONObject(dest, resultJSONObject, &err) return dest, err } diff --git a/rpc/core/consensus.go b/rpc/core/consensus.go index b97c6155c..17b878771 100644 --- a/rpc/core/consensus.go +++ b/rpc/core/consensus.go @@ -1,7 +1,7 @@ package core import ( - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" cm "github.com/tendermint/tendermint/consensus" ctypes "github.com/tendermint/tendermint/rpc/core/types" sm "github.com/tendermint/tendermint/state" @@ -33,7 +33,7 @@ func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) { // TODO: clean this up? peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState) peerRoundState := peerState.GetRoundState() - peerRoundStateStr := peer.Key + ":" + string(binary.JSONBytes(peerRoundState)) + peerRoundStateStr := peer.Key + ":" + string(wire.JSONBytes(peerRoundState)) peerRoundStates = append(peerRoundStates, peerRoundStateStr) } return &ctypes.ResponseDumpConsensusState{roundState.String(), peerRoundStates}, nil diff --git a/rpc/core_client/client.go b/rpc/core_client/client.go index 0d71b1c46..34ecddb94 100644 --- a/rpc/core_client/client.go +++ b/rpc/core_client/client.go @@ -3,7 +3,7 @@ package core_client import ( "bytes" "fmt" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" rpctypes "github.com/tendermint/tendermint/rpc/types" "io/ioutil" "net/http" @@ -85,7 +85,7 @@ func argsToJson(args ...interface{}) ([]string, error) { n, err := new(int64), new(error) for i, a := range args { buf := new(bytes.Buffer) - binary.WriteJSON(a, buf, n, err) + wire.WriteJSON(a, buf, n, err) if *err != nil { return nil, *err } @@ -95,7 +95,7 @@ func argsToJson(args ...interface{}) ([]string, error) { } func (c *ClientJSON) RequestResponse(s rpctypes.RPCRequest) (b []byte, err error) { - b = binary.JSONBytes(s) + b = wire.JSONBytes(s) buf := bytes.NewBuffer(b) resp, err := http.Post(c.addr, "text/json", buf) if err != nil { @@ -124,7 +124,7 @@ func binaryWriter(args ...interface{}) ([]interface{}, error) { list := []interface{}{} for _, a := range args { buf, n, err := new(bytes.Buffer), new(int64), new(error) - binary.WriteJSON(a, buf, n, err) + wire.WriteJSON(a, buf, n, err) if *err != nil { return nil, *err } @@ -159,7 +159,7 @@ func argsToURLValues(argNames []string, args ...interface{}) (url.Values, error) // import statements we will need for the templates /*rpc-gen:imports: -github.com/tendermint/tendermint/binary +github.com/tendermint/tendermint/wire rpctypes github.com/tendermint/tendermint/rpc/types net/http io/ioutil @@ -185,7 +185,7 @@ fmt Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -215,7 +215,7 @@ fmt Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } diff --git a/rpc/core_client/client_methods.go b/rpc/core_client/client_methods.go index 9345b82e9..425568487 100644 --- a/rpc/core_client/client_methods.go +++ b/rpc/core_client/client_methods.go @@ -5,7 +5,7 @@ package core_client import ( "fmt" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/types" sm "github.com/tendermint/tendermint/state" @@ -56,7 +56,7 @@ func (c *ClientHTTP) BlockchainInfo(minHeight int, maxHeight int) (*ctypes.Respo Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -86,7 +86,7 @@ func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -116,7 +116,7 @@ func (c *ClientHTTP) Call(fromAddress []byte, toAddress []byte, data []byte) (*c Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -146,7 +146,7 @@ func (c *ClientHTTP) CallCode(fromAddress []byte, code []byte, data []byte) (*ct Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -176,7 +176,7 @@ func (c *ClientHTTP) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, e Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -206,7 +206,7 @@ func (c *ClientHTTP) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -236,7 +236,7 @@ func (c *ClientHTTP) GenPrivAccount() (*acm.PrivAccount, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -266,7 +266,7 @@ func (c *ClientHTTP) Genesis() (*sm.GenesisDoc, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -296,7 +296,7 @@ func (c *ClientHTTP) GetAccount(address []byte) (*acm.Account, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -326,7 +326,7 @@ func (c *ClientHTTP) GetBlock(height int) (*ctypes.ResponseGetBlock, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -356,7 +356,7 @@ func (c *ClientHTTP) GetName(name string) (*types.NameRegEntry, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -386,7 +386,7 @@ func (c *ClientHTTP) GetStorage(address []byte, key []byte) (*ctypes.ResponseGet Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -416,7 +416,7 @@ func (c *ClientHTTP) ListAccounts() (*ctypes.ResponseListAccounts, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -446,7 +446,7 @@ func (c *ClientHTTP) ListNames() (*ctypes.ResponseListNames, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -476,7 +476,7 @@ func (c *ClientHTTP) ListUnconfirmedTxs() ([]types.Tx, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -506,7 +506,7 @@ func (c *ClientHTTP) ListValidators() (*ctypes.ResponseListValidators, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -536,7 +536,7 @@ func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -566,7 +566,7 @@ func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -596,7 +596,7 @@ func (c *ClientHTTP) Status() (*ctypes.ResponseStatus, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -623,7 +623,7 @@ func (c *ClientJSON) BlockchainInfo(minHeight int, maxHeight int) (*ctypes.Respo Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -650,7 +650,7 @@ func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -677,7 +677,7 @@ func (c *ClientJSON) Call(fromAddress []byte, toAddress []byte, data []byte) (*c Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -704,7 +704,7 @@ func (c *ClientJSON) CallCode(fromAddress []byte, code []byte, data []byte) (*ct Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -731,7 +731,7 @@ func (c *ClientJSON) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, e Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -758,7 +758,7 @@ func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -785,7 +785,7 @@ func (c *ClientJSON) GenPrivAccount() (*acm.PrivAccount, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -812,7 +812,7 @@ func (c *ClientJSON) Genesis() (*sm.GenesisDoc, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -839,7 +839,7 @@ func (c *ClientJSON) GetAccount(address []byte) (*acm.Account, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -866,7 +866,7 @@ func (c *ClientJSON) GetBlock(height int) (*ctypes.ResponseGetBlock, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -893,7 +893,7 @@ func (c *ClientJSON) GetName(name string) (*types.NameRegEntry, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -920,7 +920,7 @@ func (c *ClientJSON) GetStorage(address []byte, key []byte) (*ctypes.ResponseGet Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -947,7 +947,7 @@ func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -974,7 +974,7 @@ func (c *ClientJSON) ListNames() (*ctypes.ResponseListNames, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -1001,7 +1001,7 @@ func (c *ClientJSON) ListUnconfirmedTxs() ([]types.Tx, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -1028,7 +1028,7 @@ func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -1055,7 +1055,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -1082,7 +1082,7 @@ func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } @@ -1109,7 +1109,7 @@ func (c *ClientJSON) Status() (*ctypes.ResponseStatus, error) { Id string `json:"id"` JSONRPC string `json:"jsonrpc"` } - binary.ReadJSON(&response, body, &err) + wire.ReadJSON(&response, body, &err) if err != nil { return nil, err } diff --git a/rpc/server/handlers.go b/rpc/server/handlers.go index 0470135be..58b51e95a 100644 --- a/rpc/server/handlers.go +++ b/rpc/server/handlers.go @@ -12,7 +12,7 @@ import ( "time" "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/events" . "github.com/tendermint/tendermint/rpc/types" @@ -138,7 +138,7 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, params []interface{}) ([]reflect.Value, func _jsonObjectToArg(ty reflect.Type, object interface{}) (reflect.Value, error) { var err error v := reflect.New(ty) - binary.ReadJSONObjectPtr(v.Interface(), object, &err) + wire.ReadJSONObjectPtr(v.Interface(), object, &err) if err != nil { return v, err } @@ -191,7 +191,7 @@ func httpParamsToArgs(rpcFunc *RPCFunc, r *http.Request) ([]reflect.Value, error func _jsonStringToArg(ty reflect.Type, arg string) (reflect.Value, error) { var err error v := reflect.New(ty) - binary.ReadJSONPtr(v.Interface(), []byte(arg), &err) + wire.ReadJSONPtr(v.Interface(), []byte(arg), &err) if err != nil { return v, err } @@ -390,7 +390,7 @@ func (wsc *WSConnection) writeRoutine() { return case msg := <-wsc.writeChan: buf := new(bytes.Buffer) - binary.WriteJSON(msg, buf, n, err) + wire.WriteJSON(msg, buf, n, err) if *err != nil { log.Error("Failed to marshal RPCResponse to JSON", "error", err) } else { diff --git a/rpc/server/http_server.go b/rpc/server/http_server.go index 63f5d41f4..6d03668f6 100644 --- a/rpc/server/http_server.go +++ b/rpc/server/http_server.go @@ -11,7 +11,7 @@ import ( "time" "github.com/tendermint/tendermint/alert" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/rpc/types" ) @@ -34,7 +34,7 @@ func StartHTTPServer(listenAddr string, handler http.Handler) (net.Listener, err func WriteRPCResponse(w http.ResponseWriter, res RPCResponse) { buf, n, err := new(bytes.Buffer), new(int64), new(error) - binary.WriteJSON(res, buf, n, err) + wire.WriteJSON(res, buf, n, err) if *err != nil { log.Warn("Failed to write RPC response", "error", err) } diff --git a/rpc/test/ws_helpers.go b/rpc/test/ws_helpers.go index 830ef14dd..985ad86b8 100644 --- a/rpc/test/ws_helpers.go +++ b/rpc/test/ws_helpers.go @@ -9,7 +9,7 @@ import ( "time" "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" _ "github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/rpc/server" "github.com/tendermint/tendermint/rpc/types" @@ -149,7 +149,7 @@ func unmarshalResponseNewBlock(b []byte) (*types.Block, error) { Error string `json:"error"` } var err error - binary.ReadJSON(&response, b, &err) + wire.ReadJSON(&response, b, &err) if err != nil { return nil, err } @@ -194,7 +194,7 @@ func unmarshalValidateSend(amt int64, toAddr []byte) func(string, []byte) error Error string `json:"error"` } var err error - binary.ReadJSON(&response, b, &err) + wire.ReadJSON(&response, b, &err) if err != nil { return err } @@ -235,7 +235,7 @@ func unmarshalValidateCall(amt int64, returnCode []byte) func(string, []byte) er Error string `json:"error"` } var err error - binary.ReadJSON(&response, b, &err) + wire.ReadJSON(&response, b, &err) if err != nil { return err } @@ -273,7 +273,7 @@ func unmarshalValidateCallCall(origin, returnCode []byte, txid *[]byte) func(str Error string `json:"error"` } var err error - binary.ReadJSON(&response, b, &err) + wire.ReadJSON(&response, b, &err) if err != nil { return err } diff --git a/state/block_cache.go b/state/block_cache.go index 3198c3b95..e30e41218 100644 --- a/state/block_cache.go +++ b/state/block_cache.go @@ -5,7 +5,7 @@ import ( "sort" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" dbm "github.com/tendermint/tendermint/db" "github.com/tendermint/tendermint/merkle" @@ -14,8 +14,8 @@ import ( func makeStorage(db dbm.DB, root []byte) merkle.Tree { storage := merkle.NewIAVLTree( - binary.BasicCodec, - binary.BasicCodec, + wire.BasicCodec, + wire.BasicCodec, 1024, db, ) diff --git a/state/genesis.go b/state/genesis.go index 03a6dd2aa..38981c44d 100644 --- a/state/genesis.go +++ b/state/genesis.go @@ -6,7 +6,7 @@ import ( "time" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" dbm "github.com/tendermint/tendermint/db" "github.com/tendermint/tendermint/merkle" @@ -58,7 +58,7 @@ type GenesisDoc struct { func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) { var err error - binary.ReadJSONPtr(&genState, jsonBlob, &err) + wire.ReadJSONPtr(&genState, jsonBlob, &err) if err != nil { log.Error(Fmt("Couldn't read GenesisDoc: %v", err)) os.Exit(1) @@ -86,7 +86,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State { } // Make accounts state tree - accounts := merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db) + accounts := merkle.NewIAVLTree(wire.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db) for _, genAcc := range genDoc.Accounts { perm := ptypes.ZeroAccountPermissions if genAcc.Permissions != nil { @@ -122,7 +122,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State { accounts.Set(permsAcc.Address, permsAcc) // Make validatorInfos state tree && validators slice - validatorInfos := merkle.NewIAVLTree(binary.BasicCodec, ValidatorInfoCodec, 0, db) + validatorInfos := merkle.NewIAVLTree(wire.BasicCodec, ValidatorInfoCodec, 0, db) validators := make([]*Validator, len(genDoc.Validators)) for i, val := range genDoc.Validators { pubKey := val.PubKey @@ -153,7 +153,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State { } // Make namereg tree - nameReg := merkle.NewIAVLTree(binary.BasicCodec, NameRegCodec, 0, db) + nameReg := merkle.NewIAVLTree(wire.BasicCodec, NameRegCodec, 0, db) // TODO: add names, contracts to genesis.json // IAVLTrees must be persisted before copy operations. diff --git a/state/priv_validator.go b/state/priv_validator.go index 615104ffd..3df14622f 100644 --- a/state/priv_validator.go +++ b/state/priv_validator.go @@ -8,7 +8,7 @@ import ( "sync" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/types" @@ -72,7 +72,7 @@ func LoadPrivValidator(filePath string) *PrivValidator { if err != nil { Exit(err.Error()) } - privVal := binary.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator) + privVal := wire.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator) if err != nil { Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err)) } @@ -96,7 +96,7 @@ func (privVal *PrivValidator) save() { if privVal.filePath == "" { PanicSanity("Cannot save PrivValidator: filePath not set") } - jsonBytes := binary.JSONBytes(privVal) + jsonBytes := wire.JSONBytes(privVal) err := WriteFileAtomic(privVal.filePath, jsonBytes) if err != nil { // `@; BOOM!!! diff --git a/state/state.go b/state/state.go index 9282dcbf3..63782be47 100644 --- a/state/state.go +++ b/state/state.go @@ -6,7 +6,7 @@ import ( "time" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" dbm "github.com/tendermint/tendermint/db" "github.com/tendermint/tendermint/events" @@ -49,22 +49,22 @@ func LoadState(db dbm.DB) *State { return nil } else { r, n, err := bytes.NewReader(buf), new(int64), new(error) - s.ChainID = binary.ReadString(r, n, err) - s.LastBlockHeight = binary.ReadVarint(r, n, err) - s.LastBlockHash = binary.ReadByteSlice(r, n, err) - s.LastBlockParts = binary.ReadBinary(types.PartSetHeader{}, r, n, err).(types.PartSetHeader) - s.LastBlockTime = binary.ReadTime(r, n, err) - s.BondedValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) - s.LastBondedValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) - s.UnbondingValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) - accountsHash := binary.ReadByteSlice(r, n, err) - s.accounts = merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db) + s.ChainID = wire.ReadString(r, n, err) + s.LastBlockHeight = wire.ReadVarint(r, n, err) + s.LastBlockHash = wire.ReadByteSlice(r, n, err) + s.LastBlockParts = wire.ReadBinary(types.PartSetHeader{}, r, n, err).(types.PartSetHeader) + s.LastBlockTime = wire.ReadTime(r, n, err) + s.BondedValidators = wire.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) + s.LastBondedValidators = wire.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) + s.UnbondingValidators = wire.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) + accountsHash := wire.ReadByteSlice(r, n, err) + s.accounts = merkle.NewIAVLTree(wire.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db) s.accounts.Load(accountsHash) - validatorInfosHash := binary.ReadByteSlice(r, n, err) - s.validatorInfos = merkle.NewIAVLTree(binary.BasicCodec, ValidatorInfoCodec, 0, db) + validatorInfosHash := wire.ReadByteSlice(r, n, err) + s.validatorInfos = merkle.NewIAVLTree(wire.BasicCodec, ValidatorInfoCodec, 0, db) s.validatorInfos.Load(validatorInfosHash) - nameRegHash := binary.ReadByteSlice(r, n, err) - s.nameReg = merkle.NewIAVLTree(binary.BasicCodec, NameRegCodec, 0, db) + nameRegHash := wire.ReadByteSlice(r, n, err) + s.nameReg = merkle.NewIAVLTree(wire.BasicCodec, NameRegCodec, 0, db) s.nameReg.Load(nameRegHash) if *err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED @@ -80,17 +80,17 @@ func (s *State) Save() { s.validatorInfos.Save() s.nameReg.Save() buf, n, err := new(bytes.Buffer), new(int64), new(error) - binary.WriteString(s.ChainID, buf, n, err) - binary.WriteVarint(s.LastBlockHeight, buf, n, err) - binary.WriteByteSlice(s.LastBlockHash, buf, n, err) - binary.WriteBinary(s.LastBlockParts, buf, n, err) - binary.WriteTime(s.LastBlockTime, buf, n, err) - binary.WriteBinary(s.BondedValidators, buf, n, err) - binary.WriteBinary(s.LastBondedValidators, buf, n, err) - binary.WriteBinary(s.UnbondingValidators, buf, n, err) - binary.WriteByteSlice(s.accounts.Hash(), buf, n, err) - binary.WriteByteSlice(s.validatorInfos.Hash(), buf, n, err) - binary.WriteByteSlice(s.nameReg.Hash(), buf, n, err) + wire.WriteString(s.ChainID, buf, n, err) + wire.WriteVarint(s.LastBlockHeight, buf, n, err) + wire.WriteByteSlice(s.LastBlockHash, buf, n, err) + wire.WriteBinary(s.LastBlockParts, buf, n, err) + wire.WriteTime(s.LastBlockTime, buf, n, err) + wire.WriteBinary(s.BondedValidators, buf, n, err) + wire.WriteBinary(s.LastBondedValidators, buf, n, err) + wire.WriteBinary(s.UnbondingValidators, buf, n, err) + wire.WriteByteSlice(s.accounts.Hash(), buf, n, err) + wire.WriteByteSlice(s.validatorInfos.Hash(), buf, n, err) + wire.WriteByteSlice(s.nameReg.Hash(), buf, n, err) if *err != nil { PanicCrisis(*err) } @@ -302,7 +302,7 @@ func (s *State) SetValidatorInfos(validatorInfos merkle.Tree) { // State.storage func (s *State) LoadStorage(hash []byte) (storage merkle.Tree) { - storage = merkle.NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 1024, s.DB) + storage = merkle.NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 1024, s.DB) storage.Load(hash) return storage } @@ -339,14 +339,14 @@ func (s *State) SetNameReg(nameReg merkle.Tree) { } func NameRegEncoder(o interface{}, w io.Writer, n *int64, err *error) { - binary.WriteBinary(o.(*types.NameRegEntry), w, n, err) + wire.WriteBinary(o.(*types.NameRegEntry), w, n, err) } func NameRegDecoder(r io.Reader, n *int64, err *error) interface{} { - return binary.ReadBinary(&types.NameRegEntry{}, r, n, err) + return wire.ReadBinary(&types.NameRegEntry{}, r, n, err) } -var NameRegCodec = binary.Codec{ +var NameRegCodec = wire.Codec{ Encode: NameRegEncoder, Decode: NameRegDecoder, } diff --git a/state/validator.go b/state/validator.go index 44e26adb4..dcc959665 100644 --- a/state/validator.go +++ b/state/validator.go @@ -6,7 +6,7 @@ import ( "io" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/types" ) @@ -29,14 +29,14 @@ func (valInfo *ValidatorInfo) Copy() *ValidatorInfo { } func ValidatorInfoEncoder(o interface{}, w io.Writer, n *int64, err *error) { - binary.WriteBinary(o.(*ValidatorInfo), w, n, err) + wire.WriteBinary(o.(*ValidatorInfo), w, n, err) } func ValidatorInfoDecoder(r io.Reader, n *int64, err *error) interface{} { - return binary.ReadBinary(&ValidatorInfo{}, r, n, err) + return wire.ReadBinary(&ValidatorInfo{}, r, n, err) } -var ValidatorInfoCodec = binary.Codec{ +var ValidatorInfoCodec = wire.Codec{ Encode: ValidatorInfoEncoder, Decode: ValidatorInfoDecoder, } @@ -99,7 +99,7 @@ func (v *Validator) String() string { } func (v *Validator) Hash() []byte { - return binary.BinaryRipemd160(v) + return wire.BinaryRipemd160(v) } //------------------------------------- @@ -109,11 +109,11 @@ var ValidatorCodec = validatorCodec{} type validatorCodec struct{} func (vc validatorCodec) Encode(o interface{}, w io.Writer, n *int64, err *error) { - binary.WriteBinary(o.(*Validator), w, n, err) + wire.WriteBinary(o.(*Validator), w, n, err) } func (vc validatorCodec) Decode(r io.Reader, n *int64, err *error) interface{} { - return binary.ReadBinary(&Validator{}, r, n, err) + return wire.ReadBinary(&Validator{}, r, n, err) } func (vc validatorCodec) Compare(o1 interface{}, o2 interface{}) int { diff --git a/types/block.go b/types/block.go index 4d476e0fd..bbb5f74a4 100644 --- a/types/block.go +++ b/types/block.go @@ -8,7 +8,7 @@ import ( "time" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/merkle" ) @@ -75,7 +75,7 @@ func (b *Block) Hash() []byte { } func (b *Block) MakePartSet() *PartSet { - return NewPartSetFromData(binary.BinaryBytes(b)) + return NewPartSetFromData(wire.BinaryBytes(b)) } // Convenience. @@ -137,7 +137,7 @@ func (h *Header) Hash() []byte { return nil } - return binary.BinaryRipemd160(h) + return wire.BinaryRipemd160(h) } func (h *Header) StringIndented(indent string) string { diff --git a/types/part_set.go b/types/part_set.go index b38ac8bca..d9c4c5dbc 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/merkle" ) @@ -76,7 +76,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) + wire.WriteTo([]byte(Fmt(`{"hash":"%X","total":%v}`, psh.Hash, psh.Total)), w, n, err) } //------------------------------------- diff --git a/types/tx.go b/types/tx.go index 4b87912ec..9bc8484d0 100644 --- a/types/tx.go +++ b/types/tx.go @@ -6,7 +6,7 @@ import ( "io" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ptypes "github.com/tendermint/tendermint/permission/types" ) @@ -71,17 +71,17 @@ const ( TxTypePermissions = byte(0x20) ) -// for binary.readReflect -var _ = binary.RegisterInterface( +// for wire.readReflect +var _ = wire.RegisterInterface( struct{ Tx }{}, - binary.ConcreteType{&SendTx{}, TxTypeSend}, - binary.ConcreteType{&CallTx{}, TxTypeCall}, - binary.ConcreteType{&NameTx{}, TxTypeName}, - binary.ConcreteType{&BondTx{}, TxTypeBond}, - binary.ConcreteType{&UnbondTx{}, TxTypeUnbond}, - binary.ConcreteType{&RebondTx{}, TxTypeRebond}, - binary.ConcreteType{&DupeoutTx{}, TxTypeDupeout}, - binary.ConcreteType{&PermissionsTx{}, TxTypePermissions}, + wire.ConcreteType{&SendTx{}, TxTypeSend}, + wire.ConcreteType{&CallTx{}, TxTypeCall}, + wire.ConcreteType{&NameTx{}, TxTypeName}, + wire.ConcreteType{&BondTx{}, TxTypeBond}, + wire.ConcreteType{&UnbondTx{}, TxTypeUnbond}, + wire.ConcreteType{&RebondTx{}, TxTypeRebond}, + wire.ConcreteType{&DupeoutTx{}, TxTypeDupeout}, + wire.ConcreteType{&PermissionsTx{}, TxTypePermissions}, ) //----------------------------------------------------------------------------- @@ -105,7 +105,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) + wire.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v,"sequence":%v}`, txIn.Address, txIn.Amount, txIn.Sequence)), w, n, err) } func (txIn *TxInput) String() string { @@ -130,7 +130,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) + wire.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v}`, txOut.Address, txOut.Amount)), w, n, err) } func (txOut *TxOutput) String() string { @@ -145,22 +145,22 @@ type SendTx struct { } func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) - binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) + wire.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) + wire.WriteTo([]byte(","), w, n, err) } } - binary.WriteTo([]byte(`],"outputs":[`), w, n, err) + wire.WriteTo([]byte(`],"outputs":[`), w, n, err) for i, out := range tx.Outputs { out.WriteSignBytes(w, n, err) if i != len(tx.Outputs)-1 { - binary.WriteTo([]byte(","), w, n, err) + wire.WriteTo([]byte(","), w, n, err) } } - binary.WriteTo([]byte(`]}]}`), w, n, err) + wire.WriteTo([]byte(`]}]}`), w, n, err) } func (tx *SendTx) String() string { @@ -178,11 +178,11 @@ type CallTx struct { } func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(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(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) + wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err) + wire.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) + wire.WriteTo([]byte(`}]}`), w, n, err) } func (tx *CallTx) String() string { @@ -199,12 +199,12 @@ type NameTx struct { } func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) - binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"data":%s,"fee":%v`, TxTypeName, jsonEscape(tx.Data), tx.Fee)), w, n, err) - binary.WriteTo([]byte(`,"input":`), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) + wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"data":%s,"fee":%v`, TxTypeName, jsonEscape(tx.Data), tx.Fee)), w, n, err) + wire.WriteTo([]byte(`,"input":`), w, n, err) tx.Input.WriteSignBytes(w, n, err) - binary.WriteTo([]byte(Fmt(`,"name":%s`, jsonEscape(tx.Name))), w, n, err) - binary.WriteTo([]byte(`}]}`), w, n, err) + wire.WriteTo([]byte(Fmt(`,"name":%s`, jsonEscape(tx.Name))), w, n, err) + wire.WriteTo([]byte(`}]}`), w, n, err) } func (tx *NameTx) ValidateStrings() error { @@ -247,24 +247,24 @@ type BondTx struct { } func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) - binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) + wire.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) + wire.WriteTo([]byte(","), w, n, err) } } - binary.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err) - binary.WriteTo(binary.JSONBytes(tx.PubKey), w, n, err) - binary.WriteTo([]byte(`,"unbond_to":[`), w, n, err) + wire.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err) + wire.WriteTo(wire.JSONBytes(tx.PubKey), w, n, err) + wire.WriteTo([]byte(`,"unbond_to":[`), w, n, err) for i, out := range tx.UnbondTo { out.WriteSignBytes(w, n, err) if i != len(tx.UnbondTo)-1 { - binary.WriteTo([]byte(","), w, n, err) + wire.WriteTo([]byte(","), w, n, err) } } - binary.WriteTo([]byte(`]}]}`), w, n, err) + wire.WriteTo([]byte(`]}]}`), w, n, err) } func (tx *BondTx) String() string { @@ -280,8 +280,8 @@ type UnbondTx struct { } func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) - binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) + wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err) } func (tx *UnbondTx) String() string { @@ -297,8 +297,8 @@ type RebondTx struct { } func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) - binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) + wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err) } func (tx *RebondTx) String() string { @@ -329,12 +329,12 @@ type PermissionsTx struct { } func (tx *PermissionsTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) - binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"args":"`, TxTypePermissions)), w, n, err) - binary.WriteJSON(tx.PermArgs, w, n, err) - binary.WriteTo([]byte(`","input":`), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) + wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"args":"`, TxTypePermissions)), w, n, err) + wire.WriteJSON(tx.PermArgs, w, n, err) + wire.WriteTo([]byte(`","input":`), w, n, err) tx.Input.WriteSignBytes(w, n, err) - binary.WriteTo([]byte(`}]}`), w, n, err) + wire.WriteTo([]byte(`}]}`), w, n, err) } func (tx *PermissionsTx) String() string { @@ -346,7 +346,7 @@ func (tx *PermissionsTx) String() string { // This should match the leaf hashes of Block.Data.Hash()'s SimpleMerkleTree. func TxID(chainID string, tx Tx) []byte { signBytes := acm.SignBytes(chainID, tx) - return binary.BinaryRipemd160(signBytes) + return wire.BinaryRipemd160(signBytes) } //-------------------------------------------------------------------------------- diff --git a/types/vote.go b/types/vote.go index 1eed092ce..c313c2497 100644 --- a/types/vote.go +++ b/types/vote.go @@ -6,7 +6,7 @@ import ( "io" acm "github.com/tendermint/tendermint/account" - "github.com/tendermint/tendermint/binary" + "github.com/tendermint/tendermint/wire" . "github.com/tendermint/tendermint/common" ) @@ -43,9 +43,9 @@ const ( ) func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - 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(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err) + wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) + wire.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err) + wire.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err) } func (vote *Vote) Copy() *Vote { diff --git a/binary/README.md b/wire/README.md similarity index 99% rename from binary/README.md rename to wire/README.md index 9a4fa714f..3108505ed 100644 --- a/binary/README.md +++ b/wire/README.md @@ -6,7 +6,7 @@ This documentation is out of date. * Pointers that don't have a declared TypeByte() are encoded with a leading 0x00 (nil) or 0x01. -# `tendermint/binary` +# `tendermint/wire` The `binary` submodule encodes primary types and structs into bytes. diff --git a/binary/binary.go b/wire/binary.go similarity index 99% rename from binary/binary.go rename to wire/binary.go index d003a0435..3dc9cabb8 100644 --- a/binary/binary.go +++ b/wire/binary.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "encoding/json" diff --git a/binary/byteslice.go b/wire/byteslice.go similarity index 98% rename from binary/byteslice.go rename to wire/byteslice.go index b7a7550a8..ee4bb941c 100644 --- a/binary/byteslice.go +++ b/wire/byteslice.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "io" diff --git a/binary/codec.go b/wire/codec.go similarity index 99% rename from binary/codec.go rename to wire/codec.go index e66fad276..63edb94aa 100644 --- a/binary/codec.go +++ b/wire/codec.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "bytes" diff --git a/binary/int.go b/wire/int.go similarity index 99% rename from binary/int.go rename to wire/int.go index 3be5f224a..c63666faf 100644 --- a/binary/int.go +++ b/wire/int.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "encoding/binary" diff --git a/binary/int_test.go b/wire/int_test.go similarity index 99% rename from binary/int_test.go rename to wire/int_test.go index 49348fae7..3baceaa4d 100644 --- a/binary/int_test.go +++ b/wire/int_test.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "bytes" diff --git a/binary/log.go b/wire/log.go similarity index 95% rename from binary/log.go rename to wire/log.go index adf434820..7b9e509a0 100644 --- a/binary/log.go +++ b/wire/log.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/log15" diff --git a/binary/reflect.go b/wire/reflect.go similarity index 99% rename from binary/reflect.go rename to wire/reflect.go index a8c160cd8..03c9deb27 100644 --- a/binary/reflect.go +++ b/wire/reflect.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "encoding/hex" @@ -442,7 +442,7 @@ func writeReflectBinary(rv reflect.Value, rt reflect.Type, opts Options, w io.Wr typeInfo = GetTypeInfo(rt) if !rv.IsValid() { // For better compatibility with other languages, - // as far as tendermint/binary is concerned, + // as far as tendermint/wire is concerned, // pointers to nil values are the same as nil. WriteByte(0x00, w, n, err) return @@ -841,7 +841,7 @@ func writeReflectJSON(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64, typeInfo = GetTypeInfo(rt) if !rv.IsValid() { // For better compatibility with other languages, - // as far as tendermint/binary is concerned, + // as far as tendermint/wire is concerned, // pointers to nil values are the same as nil. WriteTo([]byte("null"), w, n, err) return diff --git a/binary/reflect_test.go b/wire/reflect_test.go similarity index 99% rename from binary/reflect_test.go rename to wire/reflect_test.go index 6195fb90d..751e87a81 100644 --- a/binary/reflect_test.go +++ b/wire/reflect_test.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "bytes" diff --git a/binary/string.go b/wire/string.go similarity index 97% rename from binary/string.go rename to wire/string.go index f08633a04..00ee3e999 100644 --- a/binary/string.go +++ b/wire/string.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "io" diff --git a/binary/time.go b/wire/time.go similarity index 94% rename from binary/time.go rename to wire/time.go index 9c678046a..c4a573345 100644 --- a/binary/time.go +++ b/wire/time.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "io" diff --git a/binary/util.go b/wire/util.go similarity index 98% rename from binary/util.go rename to wire/util.go index 1a4a2f417..cde0aefbf 100644 --- a/binary/util.go +++ b/wire/util.go @@ -1,4 +1,4 @@ -package binary +package wire import ( "bytes"