Skip to content

Commit

Permalink
chore: config.Config was stuttering
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Oct 10, 2019
1 parent 8f6b689 commit f41d335
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 166 deletions.
12 changes: 6 additions & 6 deletions account/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func KeystoreSeal(account *Account, password string) (j []byte, e error) {
return
}
argonKey := argon2.IDKey([]byte(password), salt,
config.Config.Tuning.CryptoKdfOpslimit,
config.Config.Tuning.CryptoKdfMemlimit,
config.Config.Tuning.CryptoKdfThreads,
config.Tuning.CryptoKdfOpslimit,
config.Tuning.CryptoKdfMemlimit,
config.Tuning.CryptoKdfThreads,
kdfKeySize)

var key [kdfKeySize]byte
Expand Down Expand Up @@ -134,10 +134,10 @@ func KeystoreSeal(account *Account, password string) (j []byte, e error) {
Ciphertext: hex.EncodeToString(encrypted),
Kdf: kdf,
KdfParams: kdfParams{
Memlimit: config.Config.Tuning.CryptoKdfMemlimit,
Opslimit: config.Config.Tuning.CryptoKdfOpslimit,
Memlimit: config.Tuning.CryptoKdfMemlimit,
Opslimit: config.Tuning.CryptoKdfOpslimit,
Salt: hex.EncodeToString(salt),
Parallelism: config.Config.Tuning.CryptoKdfThreads,
Parallelism: config.Tuning.CryptoKdfThreads,
},
},
}
Expand Down
46 changes: 23 additions & 23 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func NewContextFromNode(node *naet.Node, address string) (ctx *Context) {
// SpendTx creates a spend transaction, filling in the account nonce and
// transaction TTL automatically.
func (c *Context) SpendTx(senderID string, recipientID string, amount, fee *big.Int, payload []byte) (tx *models.SpendTx, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}
Expand All @@ -162,7 +162,7 @@ func (c *Context) SpendTx(senderID string, recipientID string, amount, fee *big.
// nonce and transaction TTL automatically. It also generates a commitment ID
// and salt, later used to claim the name.
func (c *Context) NamePreclaimTx(name string, fee *big.Int) (tx *models.NamePreclaimTx, nameSalt *big.Int, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}
Expand All @@ -183,7 +183,7 @@ func (c *Context) NamePreclaimTx(name string, fee *big.Int) (tx *models.NamePrec
// NameClaimTx creates a claim transaction, filling in the account nonce and
// transaction TTL automatically.
func (c *Context) NameClaimTx(name string, nameSalt, fee *big.Int) (tx *models.NameClaimTx, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}
Expand All @@ -197,114 +197,114 @@ func (c *Context) NameClaimTx(name string, nameSalt, fee *big.Int) (tx *models.N
// NameUpdateTx creates a name update transaction, filling in the account nonce
// and transaction TTL automatically.
func (c *Context) NameUpdateTx(name string, targetAddress string) (tx *models.NameUpdateTx, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

encodedNameHash := binary.Encode(binary.PrefixName, Namehash(name))
absNameTTL, err := c.GetTTL(config.Config.Client.Names.NameTTL)
absNameTTL, err := c.GetTTL(config.Client.Names.NameTTL)
if err != nil {
return
}
// create the transaction
tx = models.NewNameUpdateTx(c.Address, encodedNameHash, []string{targetAddress}, absNameTTL, config.Config.Client.Names.ClientTTL, config.Config.Client.Fee, txTTL, accountNonce)
tx = models.NewNameUpdateTx(c.Address, encodedNameHash, []string{targetAddress}, absNameTTL, config.Client.Names.ClientTTL, config.Client.Fee, txTTL, accountNonce)

return
}

// NameTransferTx creates a name transfer transaction, filling in the account
// nonce and transaction TTL automatically.
func (c *Context) NameTransferTx(name string, recipientAddress string) (tx *models.NameTransferTx, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

encodedNameHash := binary.Encode(binary.PrefixName, Namehash(name))

tx = models.NewNameTransferTx(c.Address, encodedNameHash, recipientAddress, config.Config.Client.Fee, txTTL, accountNonce)
tx = models.NewNameTransferTx(c.Address, encodedNameHash, recipientAddress, config.Client.Fee, txTTL, accountNonce)
return
}

// NameRevokeTx creates a name revoke transaction, filling in the account nonce
// and transaction TTL automatically.
func (c *Context) NameRevokeTx(name string) (tx *models.NameRevokeTx, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

encodedNameHash := binary.Encode(binary.PrefixName, Namehash(name))

tx = models.NewNameRevokeTx(c.Address, encodedNameHash, config.Config.Client.Fee, txTTL, accountNonce)
tx = models.NewNameRevokeTx(c.Address, encodedNameHash, config.Client.Fee, txTTL, accountNonce)
return
}

// OracleRegisterTx creates an oracle register transaction, filling in the
// account nonce and transaction TTL automatically.
func (c *Context) OracleRegisterTx(querySpec, responseSpec string, queryFee *big.Int, oracleTTLType, oracleTTLValue uint64, VMVersion uint16) (tx *models.OracleRegisterTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = models.NewOracleRegisterTx(c.Address, nonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, VMVersion, config.Config.Client.Fee, ttl)
tx = models.NewOracleRegisterTx(c.Address, nonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, VMVersion, config.Client.Fee, ttl)
return tx, nil
}

// OracleExtendTx creates an oracle extend transaction, filling in the account
// nonce and transaction TTL automatically.
func (c *Context) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx *models.OracleExtendTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = models.NewOracleExtendTx(oracleID, nonce, ttlType, ttlValue, config.Config.Client.Fee, ttl)
tx = models.NewOracleExtendTx(oracleID, nonce, ttlType, ttlValue, config.Client.Fee, ttl)
return tx, nil
}

// OracleQueryTx creates an oracle query transaction, filling in the account
// nonce and transaction TTL automatically.
func (c *Context) OracleQueryTx(OracleID, Query string, QueryFee *big.Int, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64) (tx *models.OracleQueryTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = models.NewOracleQueryTx(c.Address, nonce, OracleID, Query, QueryFee, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue, config.Config.Client.Fee, ttl)
tx = models.NewOracleQueryTx(c.Address, nonce, OracleID, Query, QueryFee, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue, config.Client.Fee, ttl)
return tx, nil
}

// OracleRespondTx creates an oracle response transaction, filling in the
// account nonce and transaction TTL automatically.
func (c *Context) OracleRespondTx(OracleID string, QueryID string, Response string, TTLType uint64, TTLValue uint64) (tx *models.OracleRespondTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = models.NewOracleRespondTx(OracleID, nonce, QueryID, Response, TTLType, TTLValue, config.Config.Client.Fee, ttl)
tx = models.NewOracleRespondTx(OracleID, nonce, QueryID, Response, TTLType, TTLValue, config.Client.Fee, ttl)
return tx, nil
}

// ContractCreateTx creates a contract create transaction, filling in the
// account nonce and transaction TTL automatically.
func (c *Context) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint16, Deposit, Amount, GasLimit, Fee *big.Int) (tx *models.ContractCreateTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = models.NewContractCreateTx(c.Address, nonce, Code, VMVersion, AbiVersion, Deposit, Amount, GasLimit, config.Config.Client.GasPrice, Fee, ttl, CallData)
tx = models.NewContractCreateTx(c.Address, nonce, Code, VMVersion, AbiVersion, Deposit, Amount, GasLimit, config.Client.GasPrice, Fee, ttl, CallData)
return tx, nil
}

// ContractCallTx creates a contract call transaction,, filling in the account
// nonce and transaction TTL automatically.
func (c *Context) ContractCallTx(ContractID, CallData string, AbiVersion uint16, Amount, GasLimit, GasPrice, Fee *big.Int) (tx *models.ContractCallTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL)
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}
Expand Down Expand Up @@ -346,7 +346,7 @@ type getTransactionByHashHeighter interface {

// WaitForTransactionForXBlocks blocks until a transaction has been mined or X
// blocks have gone by, after which it returns an error. The node polling
// interval can be config.Configured with config.Config.Tuning.ChainPollInterval.
// interval can be config.Configured with config.Tuning.ChainPollInterval.
func WaitForTransactionForXBlocks(c getTransactionByHashHeighter, txHash string, x uint64) (blockHeight uint64, blockHash string, err error) {
nodeHeight, err := c.GetHeight()
if err != nil {
Expand All @@ -367,7 +367,7 @@ func WaitForTransactionForXBlocks(c getTransactionByHashHeighter, txHash string,
bh := big.Int(tx.BlockHeight)
return bh.Uint64(), *tx.BlockHash, nil
}
time.Sleep(time.Millisecond * time.Duration(config.Config.Tuning.ChainPollInterval))
time.Sleep(time.Millisecond * time.Duration(config.Tuning.ChainPollInterval))
}
return 0, "", fmt.Errorf("%v blocks have gone by and %v still isn't in a block", x, txHash)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func signFunc(cmd *cobra.Command, args []string) (err error) {
return err
}

txSignedBase64, txHash, signature, err := models.SignHashTx(account, tx, config.Config.Node.NetworkID)
txSignedBase64, txHash, signature, err := models.SignHashTx(account, tx, config.Node.NetworkID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func ttlFunc(conn naet.GetHeighter, args []string) (err error) {
errFinal := fmt.Errorf("Error getting height from the node: %v", err)
return errFinal
}
ttl = height + config.Config.Client.TTL
ttl = height + config.Client.TTL
fmt.Println(ttl)
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func compileFunc(conn naet.CompileContracter, args []string) (err error) {
return err
}

bytecode, err := conn.CompileContract(s, config.Config.Compiler.Backend)
bytecode, err := conn.CompileContract(s, config.Compiler.Backend)
fmt.Println(bytecode)
return err
}
Expand All @@ -58,7 +58,7 @@ func encodeCalldataFunc(conn naet.EncodeCalldataer, args []string) (err error) {
return err
}

callData, err := conn.EncodeCalldata(s, args[1], args[2:], config.Config.Compiler.Backend)
callData, err := conn.EncodeCalldata(s, args[1], args[2:], config.Compiler.Backend)
if err != nil {
return err
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func decodeCalldataBytecodeFunc(conn decodeCalldataer, args []string) (err error
return fmt.Errorf("%s is not bytecode", args[0])
}

r, err := conn.DecodeCalldataBytecode(args[0], args[1], config.Config.Compiler.Backend)
r, err := conn.DecodeCalldataBytecode(args[0], args[1], config.Compiler.Backend)
if err != nil {
return
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func decodeCalldataSourceFunc(conn decodeCalldataer, args []string) (err error)
return fmt.Errorf("%s is not bytecode", args[0])
}

r, err := conn.DecodeCalldataSource(source, args[1], args[2], config.Config.Compiler.Backend)
r, err := conn.DecodeCalldataSource(source, args[1], args[2], config.Compiler.Backend)

fmt.Println(*r.Function, r.Arguments)
return
Expand All @@ -145,7 +145,7 @@ func generateAciFunc(conn naet.GenerateACIer, args []string) (err error) {
return
}

aci, err := conn.GenerateACI(source, config.Config.Compiler.Backend)
aci, err := conn.GenerateACI(source, config.Compiler.Backend)
if err != nil {
return
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Execute(v string) {
// read immediately, with this helper function you can defer the reading of the
// variables until the subcommand's execution)
func newAeNode() naet.NodeInterface {
return naet.NewNode(config.Config.Node.URL, debug)
return naet.NewNode(config.Node.URL, debug)
}

// newCompiler is just a helper function that gives you a Compiler so that you don't
Expand All @@ -67,15 +67,15 @@ func init() {
// cobra.OnInitialize(initConfig)
viper.AutomaticEnv() // read in environment variables that match
viper.SetEnvPrefix("AETERNITY")
viper.SetDefault("external-api", config.Config.Node.URL)
viper.SetDefault("network-id", config.Config.Node.NetworkID)
viper.SetDefault("external-api", config.Node.URL)
viper.SetDefault("network-id", config.Node.NetworkID)

// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags, which, if defined here,
// will be global for your application.
RootCmd.PersistentFlags().StringVarP(&config.Config.Node.URL, "external-api", "u", config.Config.Node.URL, "node external API endpoint")
RootCmd.PersistentFlags().StringVarP(&config.Config.Node.NetworkID, "network-id", "n", config.Config.Node.NetworkID, "network ID for custom private net")
RootCmd.PersistentFlags().StringVarP(&config.Node.URL, "external-api", "u", config.Node.URL, "node external API endpoint")
RootCmd.PersistentFlags().StringVarP(&config.Node.NetworkID, "network-id", "n", config.Node.NetworkID, "network ID for custom private net")
RootCmd.PersistentFlags().StringVarP(&compilerURL, "compiler-url", "c", "http://localhost:3080", "Compiler URL")
RootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug")
RootCmd.PersistentFlags().BoolVar(&config.Config.Tuning.OutputFormatJSON, "json", false, "print output in json format")
RootCmd.PersistentFlags().BoolVar(&config.Tuning.OutputFormatJSON, "json", false, "print output in json format")
}
2 changes: 1 addition & 1 deletion cmd/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func printIf(title string, v interface{}) {

// PrintObject pretty print an object obtained from the api with a title
func PrintObject(title string, i interface{}) {
if config.Config.Tuning.OutputFormatJSON {
if config.Tuning.OutputFormatJSON {
j, _ := json.MarshalIndent(i, "", " ")
fmt.Printf("%s\n", j)
return
Expand Down
4 changes: 2 additions & 2 deletions cmd/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

func setPrivateNetParams() {
config.Config.Node.URL = "http://localhost:3013"
config.Config.Node.NetworkID = "ae_docker"
config.Node.URL = "http://localhost:3013"
config.Node.NetworkID = "ae_docker"
}

// dumpV serializes and prints out any swagger model in JSON. Useful when
Expand Down
14 changes: 7 additions & 7 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func txSpendFunc(ttlFunc aeternity.GetTTLFunc, nonceFunc aeternity.GetNextNonceF
// If TTL was not specified as an argument, connect to the node to calculate
// it
if ttl == 0 {
ttl, err = ttlFunc(config.Config.Client.TTL)
ttl, err = ttlFunc(config.Client.TTL)
if err != nil {
return err
}
Expand Down Expand Up @@ -156,13 +156,13 @@ func txContractCreateFunc(ttlFunc aeternity.GetTTLFunc, nonceFunc aeternity.GetN
// If TTL was not specified as an argument, connect to the node to calculate
// it
if ttl == 0 {
ttl, err = ttlFunc(config.Config.Client.TTL)
ttl, err = ttlFunc(config.Client.TTL)
if err != nil {
return err
}
}

tx := models.NewContractCreateTx(owner, nonce, contract, config.Config.Client.Contracts.VMVersion, config.Config.Client.Contracts.ABIVersion, config.Config.Client.Contracts.Deposit, config.Config.Client.Contracts.Amount, config.Config.Client.Contracts.GasLimit, config.Config.Client.GasPrice, config.Config.Client.Fee, ttl, calldata)
tx := models.NewContractCreateTx(owner, nonce, contract, config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, config.Client.Contracts.GasLimit, config.Client.GasPrice, config.Client.Fee, ttl, calldata)

txStr, err := models.SerializeTx(tx)
if err != nil {
Expand Down Expand Up @@ -211,15 +211,15 @@ func txVerifyFunc(cmd *cobra.Command, args []string) (err error) {
if !IsTransaction(txSignedBase64) {
return errors.New("Error, missing or invalid base64 encoded transaction")
}
valid, err := aeternity.VerifySignedTx(sender, txSignedBase64, config.Config.Node.NetworkID)
valid, err := aeternity.VerifySignedTx(sender, txSignedBase64, config.Node.NetworkID)
if err != nil {
err := fmt.Errorf("error while verifying signature: %s", err)
return err
}
if valid {
fmt.Printf("The signature is valid (network-id: %s)\n", config.Config.Node.NetworkID)
fmt.Printf("The signature is valid (network-id: %s)\n", config.Node.NetworkID)
} else {
message := fmt.Sprintf("The signature is invalid (expecting network-id: %s)", config.Config.Node.NetworkID)
message := fmt.Sprintf("The signature is invalid (expecting network-id: %s)", config.Node.NetworkID)
// fmt.Println(message)
err = errors.New(message)
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func init() {
txCmd.AddCommand(txDumpRawCmd)

// tx spend command
txSpendCmd.Flags().StringVar(&fee, "fee", config.Config.Client.Fee.String(), fmt.Sprintf("Set the transaction fee (default=%s)", config.Config.Client.Fee.String()))
txSpendCmd.Flags().StringVar(&fee, "fee", config.Client.Fee.String(), fmt.Sprintf("Set the transaction fee (default=%s)", config.Client.Fee.String()))
txSpendCmd.Flags().Uint64Var(&ttl, "ttl", 0, fmt.Sprintf("Set the TTL in keyblocks (default=%d)", 0))
txSpendCmd.Flags().Uint64Var(&nonce, "nonce", 0, fmt.Sprint("Set the sender account nonce, if not the chain will be queried for its value"))
txSpendCmd.Flags().StringVar(&spendTxPayload, "payload", "", fmt.Sprint("Optional text payload for Spend Transactions, which will be turned into a bytearray"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestTxVerify(t *testing.T) {
// unsigned tx_+FMMAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjCoa15iD0gACCAfQBgIHqJ/Y=
// sign with ae_mainnet
signedTx := "tx_+J0LAfhCuEBcvwtyCo3FYqmINcP6lHLH/dRDcj5rUiKDqYKhPpiQ+1SBQ66rF3gdVQ1IcANcw/IayK//YgK2dsDF1VtroQEAuFX4UwwBoQHOp63kcMn5nZ1OQAiAqG8dSbtES2LxGp67ZLvP63P+86EBHxOjsIvwAUAGYqaLadh194A87EwIZH9u1dhMeJe9UKMKhrXmIPSAAIIB9AGAx+EjLg=="
config.Config.Node.NetworkID = "ae_mainnet"
config.Node.NetworkID = "ae_mainnet"
emptyCmd := cobra.Command{}

err := txVerifyFunc(&emptyCmd, []string{alice, signedTx})
Expand Down
Loading

0 comments on commit f41d335

Please sign in to comment.