Browse Source

Config names have no dots, are under_scored.

pull/67/head
Jae Kwon 10 years ago
parent
commit
85c8850ac2
20 changed files with 97 additions and 122 deletions
  1. +7
    -7
      alert/alert.go
  2. +5
    -5
      alert/email.go
  3. +1
    -1
      cmd/tendermint/gen_validator.go
  4. +1
    -1
      cmd/tendermint/reset_priv_validator.go
  5. +32
    -50
      config/config.go
  6. +1
    -1
      consensus/state.go
  7. +1
    -1
      consensus/types/proposal.go
  8. +1
    -1
      consensus/types/proposal_test.go
  9. +3
    -3
      db/db.go
  10. +3
    -3
      logger/log.go
  11. +15
    -22
      node/node.go
  12. +4
    -4
      rpc/core/net.go
  13. +7
    -7
      rpc/test/helpers_test.go
  14. +2
    -2
      rpc/test/tests_test.go
  15. +1
    -1
      state/priv_validator.go
  16. +1
    -1
      state/state_test.go
  17. +1
    -1
      types/block.go
  18. +5
    -5
      types/tx.go
  19. +5
    -5
      types/tx_test.go
  20. +1
    -1
      types/vote.go

+ 7
- 7
alert/alert.go View File

@ -15,16 +15,16 @@ var alertCountSince int = 0
func Alert(message string) {
log.Error("<!> ALERT <!>\n" + message)
now := time.Now().Unix()
if now-lastAlertUnix > int64(config.App().GetInt("Alert.MinInterval")) {
message = fmt.Sprintf("%v:%v", config.App().GetString("Network"), message)
if now-lastAlertUnix > int64(config.App().GetInt("alert_min_interval")) {
message = fmt.Sprintf("%v:%v", config.App().GetString("network"), message)
if alertCountSince > 0 {
message = fmt.Sprintf("%v (+%v more since)", message, alertCountSince)
alertCountSince = 0
}
if len(config.App().GetString("Alert.TwilioSid")) > 0 {
if len(config.App().GetString("alert_twilio_sid")) > 0 {
go sendTwilio(message)
}
if len(config.App().GetString("Alert.EmailRecipients")) > 0 {
if len(config.App().GetString("alert_email_recipients")) > 0 {
go sendEmail(message)
}
} else {
@ -41,8 +41,8 @@ func sendTwilio(message string) {
if len(message) > 50 {
message = message[:50]
}
twilio := gotwilio.NewTwilioClient(config.App().GetString("Alert.TwilioSid"), config.App().GetString("Alert.TwilioToken"))
res, exp, err := twilio.SendSMS(config.App().GetString("Alert.TwilioFrom"), config.App().GetString("Alert.TwilioTo"), message, "", "")
twilio := gotwilio.NewTwilioClient(config.App().GetString("alert_twilio_sid"), config.App().GetString("alert_twilio_token"))
res, exp, err := twilio.SendSMS(config.App().GetString("alert_twilio_from"), config.App().GetString("alert_twilio_to"), message, "", "")
if exp != nil || err != nil {
log.Error("sendTwilio error", "res", res, "exp", exp, "error", err)
}
@ -58,7 +58,7 @@ func sendEmail(message string) {
if len(subject) > 80 {
subject = subject[:80]
}
err := SendEmail(subject, message, config.App().GetStringSlice("Alert.EmailRecipients"))
err := SendEmail(subject, message, config.App().GetStringSlice("alert_email_recipients"))
if err != nil {
log.Error("sendEmail error", "error", err, "message", message)
}


+ 5
- 5
alert/email.go View File

@ -19,7 +19,7 @@ import (
// Convenience function
func SendEmail(subject, body string, tos []string) error {
email := Compose(subject, body)
email.From = config.App().GetString("SMTP.User")
email.From = config.App().GetString("smtp_user")
email.ContentType = "text/html; charset=utf-8"
email.AddRecipients(tos...)
err := email.Send()
@ -86,12 +86,12 @@ func (e *Email) Send() error {
auth := smtp.PlainAuth(
"",
config.App().GetString("SMTP.User"),
config.App().GetString("SMTP.Password"),
config.App().GetString("SMTP.Host"),
config.App().GetString("smtp_user"),
config.App().GetString("smtp_password"),
config.App().GetString("smtp_host"),
)
conn, err := smtp.Dial(fmt.Sprintf("%v:%v", config.App().GetString("SMTP.Host"), config.App().GetString("SMTP.Port")))
conn, err := smtp.Dial(fmt.Sprintf("%v:%v", config.App().GetString("smtp_host"), config.App().GetString("smtp_port")))
if err != nil {
return err
}


+ 1
- 1
cmd/tendermint/gen_validator.go View File

@ -18,7 +18,7 @@ Paste the following JSON into your %v file
%v
`,
config.App().GetString("PrivValidatorFile"),
config.App().GetString("priv_validator_file"),
string(privValidatorJSONBytes),
)
}

+ 1
- 1
cmd/tendermint/reset_priv_validator.go View File

@ -12,7 +12,7 @@ import (
func reset_priv_validator() {
// Get PrivValidator
var privValidator *sm.PrivValidator
privValidatorFile := config.App().GetString("PrivValidatorFile")
privValidatorFile := config.App().GetString("priv_validator_file")
if _, err := os.Stat(privValidatorFile); err == nil {
privValidator = sm.LoadPrivValidator(privValidatorFile)
privValidator.LastHeight = 0


+ 32
- 50
config/config.go View File

@ -35,33 +35,14 @@ func SetApp(a *confer.Config) {
var defaultConfig = `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
Moniker = "anonymous"
Network = "tendermint_testnet4.2"
ListenAddr = "0.0.0.0:46656"
# First node to connect to. Command-line overridable.
SeedNode = ""
# Pool of seeds. Best to use these, and specify one on command line
# if needed to override
SeedNodes = ["navytoad.chaintest.net:46656", "whiteferret.chaintest.net:46656", "magentagriffin.chaintest.net:46656", "greensalamander.chaintest.net:46656", "blackshadow.chaintest.net:46656", "purpleanteater.chaintest.net:46656", "pinkpenguin.chaintest.net:46656", "polkapig.chaintest.net:46656", "128.199.230.153:8080"]
[DB]
# The only other available backend is "memdb"
Backend = "leveldb"
# Dir = "~/.tendermint/data"
[Log.Stdout]
Level = "debug"
[RPC.HTTP]
# For the RPC API HTTP server. Port required.
ListenAddr = "0.0.0.0:46657"
[Alert]
# TODO: Document options
[SMTP]
# TODO: Document options
network = "tendermint_testnet_5"
moniker = "anonymous"
node_laddr = "0.0.0.0:46656"
seeds = "goldenalchemist.chaintest.net:46656"
fast_sync = true
db_backend = "leveldb"
log_level = "debug"
rpc_laddr = "0.0.0.0:46657"
`
var DefaultGenesis = `{
@ -141,19 +122,18 @@ var DefaultGenesis = `{
// NOTE: If you change this, maybe also change defaultConfig
func initDefaults(rootDir string) {
app.SetDefault("Moniker", "anonymous")
app.SetDefault("Network", "tendermint_testnet0")
app.SetDefault("ListenAddr", "0.0.0.0:46656")
app.SetDefault("DB.Backend", "leveldb")
app.SetDefault("DB.Dir", rootDir+"/data")
app.SetDefault("Log.Stdout.Level", "info")
app.SetDefault("RPC.HTTP.ListenAddr", "0.0.0.0:46657")
app.SetDefault("GenesisFile", rootDir+"/genesis.json")
app.SetDefault("AddrBookFile", rootDir+"/addrbook.json")
app.SetDefault("PrivValidatorfile", rootDir+"/priv_validator.json")
app.SetDefault("FastSync", false)
app.SetDefault("network", "tendermint_testnet0")
app.SetDefault("genesis_file", rootDir+"/genesis.json")
app.SetDefault("moniker", "anonymous")
app.SetDefault("node_laddr", "0.0.0.0:46656")
app.SetDefault("seeds", "goldenalchemist.chaintest.net:46656")
app.SetDefault("fast_sync", true)
app.SetDefault("addrbook_file", rootDir+"/addrbook.json")
app.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
app.SetDefault("db_backend", "leveldb")
app.SetDefault("db_dir", rootDir+"/data")
app.SetDefault("log_level", "info")
app.SetDefault("rpc_laddr", "0.0.0.0:46657")
}
func Init(rootDir string) {
@ -209,11 +189,12 @@ func ParseFlags(args []string) {
// Declare flags
flags.BoolVar(&printHelp, "help", false, "Print this help message.")
flags.String("listen_addr", app.GetString("ListenAddr"), "Listen address. (0.0.0.0:0 means any interface, any port)")
flags.String("seed_node", app.GetString("SeedNode"), "Address of seed nodes")
flags.String("rpc_http_listen_addr", app.GetString("RPC.HTTP.ListenAddr"), "RPC listen address. Port required")
flags.Bool("fast_sync", app.GetBool("FastSync"), "Fast blockchain syncing")
flags.String("log_stdout_level", app.GetString("Log.Stdout.Level"), "Stdout log level")
flags.String("moniker", app.GetString("moniker"), "Node Name")
flags.String("node_laddr", app.GetString("node_laddr"), "Node listen address. (0.0.0.0:0 means any interface, any port)")
flags.String("seeds", app.GetString("seeds"), "Comma delimited seed nodes")
flags.Bool("fast_sync", app.GetBool("fast_sync"), "Fast blockchain syncing")
flags.String("rpc_laddr", app.GetString("rpc_laddr"), "RPC listen address. Port required")
flags.String("log_level", app.GetString("log_level"), "Log level")
flags.Parse(args)
if printHelp {
flags.PrintDefaults()
@ -221,11 +202,12 @@ func ParseFlags(args []string) {
}
// Merge parsed flag values onto app.
app.BindPFlag("ListenAddr", flags.Lookup("listen_addr"))
app.BindPFlag("SeedNode", flags.Lookup("seed_node"))
app.BindPFlag("FastSync", flags.Lookup("fast_sync"))
app.BindPFlag("RPC.HTTP.ListenAddr", flags.Lookup("rpc_http_listen_addr"))
app.BindPFlag("Log.Stdout.Level", flags.Lookup("log_stdout_level"))
app.BindPFlag("moniker", flags.Lookup("moniker"))
app.BindPFlag("node_laddr", flags.Lookup("node_laddr"))
app.BindPFlag("seeds", flags.Lookup("seeds"))
app.BindPFlag("fast_sync", flags.Lookup("fast_sync"))
app.BindPFlag("rpc_laddr", flags.Lookup("rpc_laddr"))
app.BindPFlag("log_level", flags.Lookup("log_level"))
// Confused?
//app.Debug()


+ 1
- 1
consensus/state.go View File

@ -657,7 +657,7 @@ func (cs *ConsensusState) RunActionPropose(height uint, round uint) {
txs := cs.mempoolReactor.Mempool.GetProposalTxs()
block = &types.Block{
Header: &types.Header{
Network: config.App().GetString("Network"),
Network: config.App().GetString("network"),
Height: cs.Height,
Time: time.Now(),
Fees: 0, // TODO fees


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

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


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

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


+ 3
- 3
db/db.go View File

@ -32,19 +32,19 @@ func GetDB(name string) DB {
if db != nil {
return db.(DB)
}
switch config.App().GetString("DB.Backend") {
switch config.App().GetString("db_backend") {
case DBBackendMemDB:
db := NewMemDB()
dbs.Set(name, db)
return db
case DBBackendLevelDB:
db, err := NewLevelDB(path.Join(config.App().GetString("DB.Dir"), name+".db"))
db, err := NewLevelDB(path.Join(config.App().GetString("db_dir"), name+".db"))
if err != nil {
panic(err)
}
dbs.Set(name, db)
return db
default:
panic(Fmt("Unknown DB backend: %v", config.App().GetString("DB.Backend")))
panic(Fmt("Unknown DB backend: %v", config.App().GetString("db_backend")))
}
}

+ 3
- 3
logger/log.go View File

@ -20,14 +20,14 @@ func Reset() {
// stdout handler
stdoutHandler := log15.LvlFilterHandler(
getLevel(config.App().GetString("Log.Stdout.Level")),
getLevel(config.App().GetString("log_level")),
log15.StreamHandler(os.Stdout, log15.TerminalFormat()),
)
handlers = append(handlers, stdoutHandler)
/*
// Maybe also write to a file.
if _logFileDir := config.App().GetString("Log.File.Dir"); _logFileDir != "" {
if _logFileDir := config.App().GetString("log_file_dir"); _logFileDir != "" {
// Create log dir if it doesn't exist
err := os.MkdirAll(_logFileDir, 0700)
if err != nil {
@ -36,7 +36,7 @@ func Reset() {
}
// File handler
handlers = append(handlers, log15.LvlFilterHandler(
getLevel(config.App().GetString("Log.File.Level")),
getLevel(config.App().GetString("log_file_level")),
log15.Must.FileHandler(_logFileDir+"/tendermint.log", log15.LogfmtFormat()),
))
}


+ 15
- 22
node/node.go View File

@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"
bc "github.com/tendermint/tendermint/blockchain"
@ -53,13 +54,13 @@ func NewNode() *Node {
stateDB := dbm.GetDB("state")
state := sm.LoadState(stateDB)
if state == nil {
state = sm.MakeGenesisStateFromFile(stateDB, config.App().GetString("GenesisFile"))
state = sm.MakeGenesisStateFromFile(stateDB, config.App().GetString("genesis_file"))
state.Save()
}
// Get PrivValidator
var privValidator *sm.PrivValidator
privValidatorFile := config.App().GetString("PrivValidatorFile")
privValidatorFile := config.App().GetString("priv_validator_file")
if _, err := os.Stat(privValidatorFile); err == nil {
privValidator = sm.LoadPrivValidator(privValidatorFile)
log.Info("Loaded PrivValidator",
@ -75,11 +76,11 @@ func NewNode() *Node {
eventSwitch.Start()
// Get PEXReactor
book := p2p.NewAddrBook(config.App().GetString("AddrBookFile"))
book := p2p.NewAddrBook(config.App().GetString("addrbook_file"))
pexReactor := p2p.NewPEXReactor(book)
// Get BlockchainReactor
bcReactor := bc.NewBlockchainReactor(state, blockStore, config.App().GetBool("FastSync"))
bcReactor := bc.NewBlockchainReactor(state, blockStore, config.App().GetBool("fast_sync"))
// Get MempoolReactor
mempool := mempl.NewMempool(state.Copy())
@ -93,7 +94,7 @@ func NewNode() *Node {
}
// so the consensus reactor won't do anything until we're synced
if config.App().GetBool("FastSync") {
if config.App().GetBool("fast_sync") {
consensusReactor.SetSyncing(true)
}
@ -155,16 +156,8 @@ func (n *Node) AddListener(l p2p.Listener) {
// NOTE: Blocking
func (n *Node) DialSeed() {
// if the single seed node is available, use only it
prioritySeed := config.App().GetString("SeedNode")
if prioritySeed != "" {
addr := p2p.NewNetAddressString(prioritySeed)
n.dialSeed(addr)
return
}
// permute the list, dial them in random order.
seeds := config.App().GetStringSlice("SeedNodes")
seeds := strings.Split(config.App().GetString("seeds"), ",")
perm := rand.Perm(len(seeds))
for i := 0; i < len(perm); i++ {
go func(i int) {
@ -195,7 +188,7 @@ func (n *Node) StartRPC() {
core.SetMempoolReactor(n.mempoolReactor)
core.SetSwitch(n.sw)
listenAddr := config.App().GetString("RPC.HTTP.ListenAddr")
listenAddr := config.App().GetString("rpc_laddr")
mux := http.NewServeMux()
rpc.RegisterEventsHandler(mux, n.evsw)
rpc.RegisterRPCFuncs(mux, core.Routes)
@ -220,8 +213,8 @@ func (n *Node) EventSwitch() *events.EventSwitch {
func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
nodeInfo := &types.NodeInfo{
Moniker: config.App().GetString("Moniker"),
Network: config.App().GetString("Network"),
Network: config.App().GetString("network"),
Moniker: config.App().GetString("moniker"),
Version: "0.2.0", // Everything is in Big Endian.
}
if !sw.IsListening() {
@ -230,11 +223,11 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
p2pListener := sw.Listeners()[0]
p2pHost := p2pListener.ExternalAddress().IP.String()
p2pPort := p2pListener.ExternalAddress().Port
rpcListenAddr := config.App().GetString("RPC.HTTP.ListenAddr")
rpcListenAddr := config.App().GetString("rpc_laddr")
_, rpcPortStr, _ := net.SplitHostPort(rpcListenAddr)
rpcPort, err := strconv.Atoi(rpcPortStr)
if err != nil {
panic(Fmt("Expected numeric RPC.HTTP.ListenAddr port but got %v", rpcPortStr))
panic(Fmt("Expected numeric RPC.ListenAddr port but got %v", rpcPortStr))
}
// We assume that the rpcListener has the same ExternalAddress.
@ -250,17 +243,17 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
func RunNode() {
// Create & start node
n := NewNode()
l := p2p.NewDefaultListener("tcp", config.App().GetString("ListenAddr"), false)
l := p2p.NewDefaultListener("tcp", config.App().GetString("node_laddr"), false)
n.AddListener(l)
n.Start()
// If seedNode is provided by config, dial out.
if config.App().GetString("SeedNode") != "" || len(config.App().GetStringSlice("SeedNodes")) != 0 {
if len(config.App().GetStringSlice("seeds")) != 0 {
n.DialSeed()
}
// Run the RPC server.
if config.App().GetString("RPC.HTTP.ListenAddr") != "" {
if config.App().GetString("rpc_laddr") != "" {
n.StartRPC()
}


+ 4
- 4
rpc/core/net.go View File

@ -12,7 +12,7 @@ import (
func Status() (*ctypes.ResponseStatus, error) {
db := dbm.NewMemDB()
genesisState := sm.MakeGenesisStateFromFile(db, config.App().GetString("GenesisFile"))
genesisState := sm.MakeGenesisStateFromFile(db, config.App().GetString("genesis_file"))
genesisHash := genesisState.Hash()
latestHeight := blockStore.Height()
var (
@ -26,15 +26,15 @@ func Status() (*ctypes.ResponseStatus, error) {
latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
}
return &ctypes.ResponseStatus{genesisHash, config.App().GetString("Network"), latestBlockHash, latestHeight, latestBlockTime}, nil
return &ctypes.ResponseStatus{genesisHash, config.App().GetString("network"), latestBlockHash, latestHeight, latestBlockTime}, nil
}
//-----------------------------------------------------------------------------
func NetInfo() (*ctypes.ResponseNetInfo, error) {
listening := p2pSwitch.IsListening()
moniker := config.App().GetString("Moniker")
network := config.App().GetString("Network")
moniker := config.App().GetString("moniker")
network := config.App().GetString("network")
listeners := []string{}
for _, listener := range p2pSwitch.Listeners() {
listeners = append(listeners, listener.String())


+ 7
- 7
rpc/test/helpers_test.go View File

@ -61,7 +61,7 @@ func decodeHex(hexStr string) []byte {
func newNode(ready chan struct{}) {
// Create & start node
node = nm.NewNode()
l := p2p.NewDefaultListener("tcp", config.App().GetString("ListenAddr"), false)
l := p2p.NewDefaultListener("tcp", config.App().GetString("node_laddr"), false)
node.AddListener(l)
node.Start()
@ -79,12 +79,12 @@ func init() {
rootDir := ".tendermint"
config.Init(rootDir)
app := config.App()
app.Set("SeedNode", "")
app.Set("DB.Backend", "memdb")
app.Set("RPC.HTTP.ListenAddr", rpcAddr)
app.Set("GenesisFile", rootDir+"/genesis.json")
app.Set("PrivValidatorFile", rootDir+"/priv_validator.json")
app.Set("Log.Stdout.Level", "debug")
app.Set("genesis_file", rootDir+"/genesis.json")
app.Set("seeds", "")
app.Set("priv_validator_file", rootDir+"/priv_validator.json")
app.Set("db_backend", "memdb")
app.Set("rpc_laddr", rpcAddr)
app.Set("log_level", "debug")
config.SetApp(app)
logger.Reset()


+ 2
- 2
rpc/test/tests_test.go View File

@ -16,9 +16,9 @@ func testStatus(t *testing.T, typ string) {
if err != nil {
t.Fatal(err)
}
if resp.Network != config.App().GetString("Network") {
if resp.Network != config.App().GetString("network") {
t.Fatal(fmt.Errorf("Network mismatch: got %s expected %s",
resp.Network, config.App().Get("Network")))
resp.Network, config.App().Get("network")))
}
}


+ 1
- 1
state/priv_validator.go View File

@ -68,7 +68,7 @@ func GenPrivValidator() *PrivValidator {
LastHeight: 0,
LastRound: 0,
LastStep: stepNone,
filename: config.App().GetString("PrivValidatorFile"),
filename: config.App().GetString("priv_validator_file"),
}
}


+ 1
- 1
state/state_test.go View File

@ -65,7 +65,7 @@ func TestCopyState(t *testing.T) {
func makeBlock(t *testing.T, state *State, commits []types.Commit, txs []types.Tx) *types.Block {
block := &types.Block{
Header: &types.Header{
Network: config.App().GetString("Network"),
Network: config.App().GetString("network"),
Height: state.LastBlockHeight + 1,
Time: state.LastBlockTime.Add(time.Minute),
Fees: 0,


+ 1
- 1
types/block.go View File

@ -24,7 +24,7 @@ type Block struct {
// Basic validation that doesn't involve state data.
func (b *Block) ValidateBasic(lastBlockHeight uint, lastBlockHash []byte,
lastBlockParts PartSetHeader, lastBlockTime time.Time) error {
if b.Network != config.App().GetString("Network") {
if b.Network != config.App().GetString("network") {
return errors.New("Wrong Block.Header.Network")
}
if b.Height != lastBlockHeight+1 {


+ 5
- 5
types/tx.go View File

@ -132,7 +132,7 @@ type SendTx struct {
func (tx *SendTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err)
for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err)
@ -166,7 +166,7 @@ type CallTx struct {
func (tx *CallTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err)
tx.Input.WriteSignBytes(w, n, err)
@ -187,7 +187,7 @@ type BondTx struct {
func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err)
@ -221,7 +221,7 @@ type UnbondTx struct {
func (tx *UnbondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
}
@ -239,7 +239,7 @@ type RebondTx struct {
func (tx *RebondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
}


+ 5
- 5
types/tx_test.go View File

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


+ 1
- 1
types/vote.go View File

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


Loading…
Cancel
Save