Skip to content

Commit

Permalink
refactor: utils.BigInt is now just a type aliased big.Int
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Jun 4, 2019
1 parent b3dc468 commit 62768a9
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 224 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ All notable changes to this project will be documented in this file. See [standa
* renamed helper function arguments to accomodate different kinds of TTLs in other transaction types ([2970997](https://github.com/aeternity/aepp-sdk-go/commit/2970997))
* renamed helper function arguments to accomodate different kinds of TTLs in other transaction types ([5697537](https://github.com/aeternity/aepp-sdk-go/commit/5697537))
* rlp Encode() was encoding 0 value of uint64 as 0x00, but big.Int 0 value as 0x80. Changed big.Int 0 value to 0x00 ([e21c6f5](https://github.com/aeternity/aepp-sdk-go/commit/e21c6f5))
* SpendTx, OracleRegisterTx RLP() methods should always use utils.BigInt.Int while serializing, not the utils.BigInt directly, because otherwise there will be a list within a list ([fcaa28d](https://github.com/aeternity/aepp-sdk-go/commit/fcaa28d))
* SpendTx, OracleRegisterTx RLP() methods should always use big.Int.Int while serializing, not the big.Int directly, because otherwise there will be a list within a list ([fcaa28d](https://github.com/aeternity/aepp-sdk-go/commit/fcaa28d))
* tx command shouldn't use BaseEncodeTx() as a returned function ([21c5a7c](https://github.com/aeternity/aepp-sdk-go/commit/21c5a7c))
* uint64/utils.BigInt instead of int64 for certain variables in config.go ([1c65c9a](https://github.com/aeternity/aepp-sdk-go/commit/1c65c9a))
* uint64/utils.BigInt instead of int64 for certain variables in config.go ([4c76f06](https://github.com/aeternity/aepp-sdk-go/commit/4c76f06))
* uint64/big.Int instead of int64 for certain variables in config.go ([1c65c9a](https://github.com/aeternity/aepp-sdk-go/commit/1c65c9a))
* uint64/big.Int instead of int64 for certain variables in config.go ([4c76f06](https://github.com/aeternity/aepp-sdk-go/commit/4c76f06))


### Features
Expand Down
46 changes: 24 additions & 22 deletions aeternity/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aeternity

import (
"math/big"

"github.com/aeternity/aepp-sdk-go/utils"
)

Expand All @@ -19,31 +21,31 @@ type NodeConfig struct {

// AensConfig configurations for Aens
type AensConfig struct {
NameTTL uint64 `json:"name_ttl" yaml:"name_ttl" mapstructure:"name_ttl"`
ClientTTL uint64 `json:"client_ttl" yaml:"client_ttl" mapstructure:"client_ttl"`
PreClaimFee utils.BigInt `json:"preclaim_fee" yaml:"preclaim_fee" mapstructure:"preclaim_fee"`
ClaimFee utils.BigInt `json:"claim_fee" yaml:"claim_fee" mapstructure:"claim_fee"`
UpdateFee utils.BigInt `json:"update_fee" yaml:"update_fee" mapstructure:"update_fee"`
NameTTL uint64 `json:"name_ttl" yaml:"name_ttl" mapstructure:"name_ttl"`
ClientTTL uint64 `json:"client_ttl" yaml:"client_ttl" mapstructure:"client_ttl"`
PreClaimFee big.Int `json:"preclaim_fee" yaml:"preclaim_fee" mapstructure:"preclaim_fee"`
ClaimFee big.Int `json:"claim_fee" yaml:"claim_fee" mapstructure:"claim_fee"`
UpdateFee big.Int `json:"update_fee" yaml:"update_fee" mapstructure:"update_fee"`
}

// ContractConfig configurations for contracts
type ContractConfig struct {
Gas utils.BigInt `json:"gas" yaml:"gas" mapstructure:"gas"`
GasPrice utils.BigInt `json:"gas_price" yaml:"gas_price" mapstructure:"gas_price"`
Amount utils.BigInt `json:"amount" yaml:"amount" mapstructure:"amount"`
Deposit uint64 `json:"deposit" yaml:"deposit" mapstructure:"deposit"`
VMVersion uint64 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
ABIVersion uint64 `json:"abi_version" yaml:"abi_version" mapstructure:"abi_version"`
Gas big.Int `json:"gas" yaml:"gas" mapstructure:"gas"`
GasPrice big.Int `json:"gas_price" yaml:"gas_price" mapstructure:"gas_price"`
Amount big.Int `json:"amount" yaml:"amount" mapstructure:"amount"`
Deposit uint64 `json:"deposit" yaml:"deposit" mapstructure:"deposit"`
VMVersion uint64 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
ABIVersion uint64 `json:"abi_version" yaml:"abi_version" mapstructure:"abi_version"`
}

// OracleConfig configurations for contracts
type OracleConfig struct {
QueryFee utils.BigInt `json:"query_fee" yaml:"query_fee" mapstructure:"query_fee"`
QueryTTLType uint64 `json:"query_ttl_type" yaml:"query_ttl_type" mapstructure:"query_ttl_type"`
QueryTTLValue uint64 `json:"query_ttl_value" yaml:"query_ttl_value" mapstructure:"query_ttl_value"`
ResponseTTLType uint64 `json:"response_ttl_type" yaml:"response_ttl_type" mapstructure:"response_ttl_type"`
ResponseTTLValue uint64 `json:"response_ttl_value" yaml:"response_ttl_value" mapstructure:"response_ttl_value"`
VMVersion uint64 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
QueryFee big.Int `json:"query_fee" yaml:"query_fee" mapstructure:"query_fee"`
QueryTTLType uint64 `json:"query_ttl_type" yaml:"query_ttl_type" mapstructure:"query_ttl_type"`
QueryTTLValue uint64 `json:"query_ttl_value" yaml:"query_ttl_value" mapstructure:"query_ttl_value"`
ResponseTTLType uint64 `json:"response_ttl_type" yaml:"response_ttl_type" mapstructure:"response_ttl_type"`
ResponseTTLValue uint64 `json:"response_ttl_value" yaml:"response_ttl_value" mapstructure:"response_ttl_value"`
VMVersion uint64 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
}

// StateChannelConfig configurations for contracts TODO: not complete
Expand All @@ -54,11 +56,11 @@ type StateChannelConfig struct {

// ClientConfig client parameters configuration
type ClientConfig struct {
BaseGas utils.BigInt
GasPerByte utils.BigInt
GasPrice utils.BigInt
BaseGas big.Int
GasPerByte big.Int
GasPrice big.Int
TTL uint64 `json:"ttl" yaml:"ttl" mapstructure:"ttl"`
Fee utils.BigInt `json:"fee" yaml:"fee" mapstructure:"fee"`
Fee big.Int `json:"fee" yaml:"fee" mapstructure:"fee"`
DefaultKey string `json:"default_key_name" yaml:"default_key_name" mapstructure:"default_key_name"`
Names AensConfig `json:"names" yaml:"names" mapstructure:"names"`
Contracts ContractConfig `json:"contracts" yaml:"contracts" mapstructure:"contracts"`
Expand Down Expand Up @@ -111,7 +113,7 @@ var Config = ProfileConfig{
Contracts: ContractConfig{
Gas: *utils.NewBigIntFromUint64(1e9),
GasPrice: *utils.NewBigIntFromUint64(1e9),
Amount: *utils.NewBigInt(),
Amount: *new(big.Int),
Deposit: 0,
VMVersion: 3,
ABIVersion: 1,
Expand Down
4 changes: 2 additions & 2 deletions aeternity/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ func uuidV4() (u string) {
// since the salt is a uint256, which Erlang handles well, but Go has nothing similar to it,
// it is imperative that the salt be kept as a bytearray unless you really have to convert it
// into an integer. Which you usually don't, because it's a salt.
func generateCommitmentID(name string) (ch string, salt *utils.BigInt, err error) {
func generateCommitmentID(name string) (ch string, salt *big.Int, err error) {
saltBytes, err := randomBytes(32)
if err != nil {
return
}

ch, err = computeCommitmentID(name, saltBytes)

salt = utils.NewBigInt()
salt = new(big.Int)
salt.SetBytes(saltBytes)

return ch, salt, err
Expand Down
18 changes: 9 additions & 9 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package aeternity
import (
"fmt"
"io/ioutil"
"math/big"
"os"
"path/filepath"
"strings"
"time"

"github.com/aeternity/aepp-sdk-go/generated/client/external"
"github.com/aeternity/aepp-sdk-go/generated/models"
"github.com/aeternity/aepp-sdk-go/utils"
)

func urlComponents(url string) (host string, schemas []string) {
Expand Down Expand Up @@ -218,7 +218,7 @@ func (client *Client) GetTTLNonce(accountID string, offset uint64) (txTTL, accou

// NamePreclaimTx creates a name preclaim transaction and salt (required for claiming)
// It should return the Tx struct, not the base64 encoded RLP, to ease subsequent inspection.
func (n *Aens) NamePreclaimTx(name string, fee utils.BigInt) (tx NamePreclaimTx, nameSalt *utils.BigInt, err error) {
func (n *Aens) NamePreclaimTx(name string, fee big.Int) (tx NamePreclaimTx, nameSalt *big.Int, err error) {
txTTL, accountNonce, err := getTTLNonce(n.Client, n.Account.Address, Config.Client.TTL)
if err != nil {
return
Expand All @@ -228,20 +228,20 @@ func (n *Aens) NamePreclaimTx(name string, fee utils.BigInt) (tx NamePreclaimTx,
// since the salt is 32 bytes long, you must use a big.Int to convert it into an integer
cm, nameSalt, err := generateCommitmentID(name)
if err != nil {
return NamePreclaimTx{}, utils.NewBigInt(), err
return NamePreclaimTx{}, new(big.Int), err
}

// build the transaction
tx = NewNamePreclaimTx(n.Account.Address, cm, fee, txTTL, accountNonce)
if err != nil {
return NamePreclaimTx{}, utils.NewBigInt(), err
return NamePreclaimTx{}, new(big.Int), err
}

return
}

// NameClaimTx creates a claim transaction
func (n *Aens) NameClaimTx(name string, nameSalt utils.BigInt, fee utils.BigInt) (tx NameClaimTx, err error) {
func (n *Aens) NameClaimTx(name string, nameSalt big.Int, fee big.Int) (tx NameClaimTx, err error) {
txTTL, accountNonce, err := getTTLNonce(n.Client, n.Account.Address, Config.Client.TTL)
if err != nil {
return
Expand Down Expand Up @@ -298,7 +298,7 @@ func (n *Aens) NameRevokeTx(name string, recipientAddress string) (tx NameRevoke
}

// OracleRegisterTx create a new oracle
func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee utils.BigInt, oracleTTLType, oracleTTLValue, abiVersion uint64, vmVersion uint64) (tx OracleRegisterTx, err error) {
func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee big.Int, oracleTTLType, oracleTTLValue, abiVersion uint64, vmVersion uint64) (tx OracleRegisterTx, err error) {
ttl, nonce, err := getTTLNonce(o.Client, o.Account.Address, Config.Client.TTL)
if err != nil {
return OracleRegisterTx{}, err
Expand All @@ -320,7 +320,7 @@ func (o *Oracle) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx O
}

// OracleQueryTx ask something of an oracle
func (o *Oracle) OracleQueryTx(OracleID, Query string, QueryFee utils.BigInt, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64) (tx OracleQueryTx, err error) {
func (o *Oracle) OracleQueryTx(OracleID, Query string, QueryFee big.Int, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64) (tx OracleQueryTx, err error) {
ttl, nonce, err := getTTLNonce(o.Client, o.Account.Address, Config.Client.TTL)
if err != nil {
return OracleQueryTx{}, err
Expand All @@ -341,7 +341,7 @@ func (o *Oracle) OracleRespondTx(OracleID string, QueryID string, Response strin
return tx, nil
}

func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion, Deposit uint64, Amount, Gas, GasPrice, Fee utils.BigInt) (tx ContractCreateTx, err error) {
func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion, Deposit uint64, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCreateTx, err error) {
ttl, nonce, err := getTTLNonce(c.Client, c.Account.Address, Config.Client.TTL)
if err != nil {
return ContractCreateTx{}, err
Expand All @@ -351,7 +351,7 @@ func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, Abi
return tx, nil
}

func (c *Contract) ContractCallTx(ContractID, CallData string, VMVersion, AbiVersion uint64, Amount, Gas, GasPrice, Fee utils.BigInt) (tx ContractCallTx, err error) {
func (c *Contract) ContractCallTx(ContractID, CallData string, VMVersion, AbiVersion uint64, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCallTx, err error) {
ttl, nonce, err := getTTLNonce(c.Client, c.Account.Address, Config.Client.TTL)
if err != nil {
return ContractCallTx{}, err
Expand Down
4 changes: 2 additions & 2 deletions aeternity/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package aeternity
import (
"encoding/json"
"fmt"
"math/big"
"reflect"

"time"

"github.com/aeternity/aepp-sdk-go/generated/models"
"github.com/aeternity/aepp-sdk-go/utils"
)

func times(str string, n int) (out string) {
Expand Down Expand Up @@ -69,7 +69,7 @@ func printIf(title string, v interface{}) {
p(title, n, v.Elem(), dept)
case reflect.Struct:
if v.Type().Name() == "BigInt" {
vc := v.Interface().(utils.BigInt)
vc := v.Interface().(big.Int)
PpI(dept, "Balance", vc.Text(10))
} else {
PpT(dept, fmt.Sprintf("<%s>", v.Type().Name()))
Expand Down
4 changes: 2 additions & 2 deletions aeternity/terminal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
func Test_printIf_BigIntBalancePrinted(t *testing.T) {
type args struct {
title string
v *utils.BigInt
v *big.Int
}
tests := []struct {
name string
args args
}{
{
name: "Test that printIf() recognizes the utils.BigInt special case",
name: "Test that printIf() recognizes the big.Int special case",
args: args{
title: "Title",
v: utils.NewBigIntFromUint64(1377),
Expand Down

0 comments on commit 62768a9

Please sign in to comment.