// make a send tx (uses get account to figure out the nonce) func makeSendTx(t *testing.T, typ string, from, to []byte, amt uint64) *types.SendTx { acc := getAccount(t, typ, from) nonce := 0 if acc != nil { nonce = int(acc.Sequence) + 1 } bytePub, err := hex.DecodeString(userPub) if err != nil { t.Fatal(err) } tx := &types.SendTx{ Inputs: []*types.TxInput{ &types.TxInput{ Address: from, Amount: amt, Sequence: uint(nonce), Signature: account.SignatureEd25519{}, PubKey: account.PubKeyEd25519(bytePub), }, }, Outputs: []*types.TxOutput{ &types.TxOutput{ Address: to, Amount: amt, }, }, } return tx }
// make a call tx (uses get account to figure out the nonce) func makeCallTx(t *testing.T, typ string, from, to, data []byte, amt, gaslim, fee uint64) *types.CallTx { acc := getAccount(t, typ, from) nonce := 0 if acc != nil { nonce = int(acc.Sequence) + 1 } bytePub, err := hex.DecodeString(userPub) if err != nil { t.Fatal(err) } tx := &types.CallTx{ Input: &types.TxInput{ Address: from, Amount: amt, Sequence: uint(nonce), Signature: account.SignatureEd25519{}, PubKey: account.PubKeyEd25519(bytePub), }, Address: to, GasLimit: gaslim, Fee: fee, Data: data, } return tx }
func randValidator_() *Validator { return &Validator{ Address: RandBytes(20), PubKey: account.PubKeyEd25519(RandBytes(64)), BondHeight: uint(RandUint32()), VotingPower: RandUint64(), Accum: int64(RandUint64()), } }
// Generates a new validator with private key. func GenPrivValidator() *PrivValidator { privKeyBytes := new([64]byte) copy(privKeyBytes[:32], CRandBytes(32)) pubKeyBytes := ed25519.MakePublicKey(privKeyBytes) pubKey := acm.PubKeyEd25519(*pubKeyBytes) privKey := acm.PrivKeyEd25519(*privKeyBytes) return &PrivValidator{ Address: pubKey.Address(), PubKey: pubKey, PrivKey: privKey, LastHeight: 0, LastRound: 0, LastStep: stepNone, filePath: "", } }
// initialize config and create new node func init() { // Save new priv_validator file. priv := &state.PrivValidator{ Address: decodeHex(userAddr), PubKey: account.PubKeyEd25519(decodeHex(userPub)), PrivKey: account.PrivKeyEd25519(decodeHex(userPriv)), } priv.SetFile(config.GetString("priv_validator_file")) priv.Save() consensus.RoundDuration0 = 3 * time.Second consensus.RoundDurationDelta = 1 * time.Second // start a node ready := make(chan struct{}) go newNode(ready) <-ready }
// initialize config and create new node func init() { chainID = config.GetString("chain_id") // Save new priv_validator file. priv := &types.PrivValidator{ Address: user[0].Address, PubKey: acm.PubKeyEd25519(user[0].PubKey.(acm.PubKeyEd25519)), PrivKey: acm.PrivKeyEd25519(user[0].PrivKey.(acm.PrivKeyEd25519)), } priv.SetFile(config.GetString("priv_validator_file")) priv.Save() // TODO: change consensus/state.go timeouts to be shorter // start a node ready := make(chan struct{}) go newNode(ready) <-ready }
func randPubKey() account.PubKeyEd25519 { var pubKey [32]byte copy(pubKey[:], RandBytes(32)) return account.PubKeyEd25519(pubKey) }