Skip to content

Commit

Permalink
refactor: standardize on *big.Int being passed everywhere, not big.Int
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Oct 10, 2019
1 parent e613f71 commit 1311831
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 219 deletions.
32 changes: 16 additions & 16 deletions aeternity/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ type ContractConfig struct {
// * the base gas;
// * other gas components, such as gas proportional to the byte size of the
// transaction or relative TTL, gas needed for contract execution.
GasLimit big.Int `json:"gas" yaml:"gas" mapstructure:"gas"`
GasLimit *big.Int `json:"gas" yaml:"gas" mapstructure:"gas"`
// Amount is an optional amount to transfer to the contract account.
Amount big.Int `json:"amount" yaml:"amount" mapstructure:"amount"`
Amount *big.Int `json:"amount" yaml:"amount" mapstructure:"amount"`
// Deposit will be "held by the contract" until it is deactivated.
Deposit big.Int `json:"deposit" yaml:"deposit" mapstructure:"deposit"`
Deposit *big.Int `json:"deposit" yaml:"deposit" mapstructure:"deposit"`
// VMVersion indicates which virtual machine should be used for bytecode execution.
VMVersion uint16 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
// ABIVersion indicates the binary interface/calling convention used by the contract.
Expand All @@ -84,7 +84,7 @@ type OracleConfig struct {
// QueryFee is locked up until the oracle answers (and gets the fee) or the
// transaction TTL expires (and the sender is refunded). In other words, it
// is a bounty.
QueryFee big.Int `json:"query_fee" yaml:"query_fee" mapstructure:"query_fee"`
QueryFee *big.Int `json:"query_fee" yaml:"query_fee" mapstructure:"query_fee"`
// QueryTTLType indicates whether the TTLValue should be interpreted as an absolute or delta blockheight.
QueryTTLType uint64 `json:"query_ttl_type" yaml:"query_ttl_type" mapstructure:"query_ttl_type"`
// QueryTTLValue indicates how long the query is open for response from the oracle.
Expand All @@ -105,16 +105,16 @@ type StateChannelConfig struct {
// ClientConfig client parameters configuration
type ClientConfig struct {
// BaseGas is one component of transaction fee calculation.
BaseGas big.Int `json:"base_gas" yaml:"base_gas" mapstructure:"base_gas"`
BaseGas *big.Int `json:"base_gas" yaml:"base_gas" mapstructure:"base_gas"`
// GasPerByte is multiplied by the RLP serialized transaction's length.
GasPerByte big.Int `json:"gas_per_byte" yaml:"gas_per_byte" mapstructure:"gas_per_byte"`
GasPerByte *big.Int `json:"gas_per_byte" yaml:"gas_per_byte" mapstructure:"gas_per_byte"`
// GasPrice is the conversion factor from gas to AE.
GasPrice big.Int `json:"gas_price" yaml:"gas_price" mapstructure:"gas_price"`
GasPrice *big.Int `json:"gas_price" yaml:"gas_price" mapstructure:"gas_price"`
// TTL is the default blockheight offset that will be added to the current
// height to determine a transaction's TTL.
TTL uint64 `json:"ttl" yaml:"ttl" mapstructure:"ttl"`
// Fee is a default transaction fee that should be big enough for most transaction types.
Fee big.Int `json:"fee" yaml:"fee" mapstructure:"fee"`
Fee *big.Int `json:"fee" yaml:"fee" mapstructure:"fee"`
Names AensConfig `json:"names" yaml:"names" mapstructure:"names"`
Contracts ContractConfig `json:"contracts" yaml:"contracts" mapstructure:"contracts"`
Oracles OracleConfig `json:"oracles" yaml:"oracles" mapstructure:"oracles"`
Expand Down Expand Up @@ -154,25 +154,25 @@ var Config = ProfileConfig{
Backend: CompilerBackendAEVM,
},
Client: ClientConfig{
BaseGas: *utils.NewIntFromUint64(15000),
GasPerByte: *utils.NewIntFromUint64(20),
GasPrice: *utils.NewIntFromUint64(1e9),
BaseGas: utils.NewIntFromUint64(15000),
GasPerByte: utils.NewIntFromUint64(20),
GasPrice: utils.NewIntFromUint64(1e9),
TTL: 500,
Fee: *utils.RequireIntFromString("200000000000000"),
Fee: utils.RequireIntFromString("200000000000000"),
Names: AensConfig{
NameTTL: 500,
ClientTTL: 500,
},
Contracts: ContractConfig{
CompilerURL: "http://localhost:3080",
GasLimit: *utils.NewIntFromUint64(1e9),
Amount: *new(big.Int),
Deposit: *new(big.Int),
GasLimit: utils.NewIntFromUint64(1e9),
Amount: new(big.Int),
Deposit: new(big.Int),
VMVersion: 4,
ABIVersion: 1,
},
Oracles: OracleConfig{
QueryFee: *utils.NewIntFromUint64(0),
QueryFee: utils.NewIntFromUint64(0),
QueryTTLType: OracleTTLTypeDelta,
QueryTTLValue: 300,
ResponseTTLType: OracleTTLTypeDelta,
Expand Down
14 changes: 7 additions & 7 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func NewContextFromNode(node *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 *SpendTx, err error) {
func (c *Context) SpendTx(senderID string, recipientID string, amount, fee *big.Int, payload []byte) (tx *SpendTx, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, Config.Client.TTL)
if err != nil {
return
Expand All @@ -159,7 +159,7 @@ func (c *Context) SpendTx(senderID string, recipientID string, amount, fee big.I
// NamePreclaimTx creates a name preclaim transaction, filling in the account
// 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 *NamePreclaimTx, nameSalt *big.Int, err error) {
func (c *Context) NamePreclaimTx(name string, fee *big.Int) (tx *NamePreclaimTx, nameSalt *big.Int, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, Config.Client.TTL)
if err != nil {
return
Expand All @@ -180,7 +180,7 @@ func (c *Context) NamePreclaimTx(name string, fee big.Int) (tx *NamePreclaimTx,

// NameClaimTx creates a claim transaction, filling in the account nonce and
// transaction TTL automatically.
func (c *Context) NameClaimTx(name string, nameSalt big.Int, fee big.Int) (tx *NameClaimTx, err error) {
func (c *Context) NameClaimTx(name string, nameSalt, fee *big.Int) (tx *NameClaimTx, err error) {
txTTL, accountNonce, err := c.GetTTLNonce(c.Address, Config.Client.TTL)
if err != nil {
return
Expand Down Expand Up @@ -241,7 +241,7 @@ func (c *Context) NameRevokeTx(name string) (tx *NameRevokeTx, err error) {

// 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 *OracleRegisterTx, err error) {
func (c *Context) OracleRegisterTx(querySpec, responseSpec string, queryFee *big.Int, oracleTTLType, oracleTTLValue uint64, VMVersion uint16) (tx *OracleRegisterTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, Config.Client.TTL)
if err != nil {
return
Expand All @@ -265,7 +265,7 @@ func (c *Context) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx

// 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 *OracleQueryTx, err error) {
func (c *Context) OracleQueryTx(OracleID, Query string, QueryFee *big.Int, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64) (tx *OracleQueryTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, Config.Client.TTL)
if err != nil {
return
Expand All @@ -289,7 +289,7 @@ func (c *Context) OracleRespondTx(OracleID string, QueryID string, Response stri

// 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 *ContractCreateTx, err error) {
func (c *Context) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint16, Deposit, Amount, GasLimit, Fee *big.Int) (tx *ContractCreateTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, Config.Client.TTL)
if err != nil {
return
Expand All @@ -301,7 +301,7 @@ func (c *Context) ContractCreateTx(Code string, CallData string, VMVersion, AbiV

// 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 *ContractCallTx, err error) {
func (c *Context) ContractCallTx(ContractID, CallData string, AbiVersion uint16, Amount, GasLimit, GasPrice, Fee *big.Int) (tx *ContractCallTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, Config.Client.TTL)
if err != nil {
return
Expand Down
12 changes: 6 additions & 6 deletions aeternity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ func calcFeeStd(tx rlp.Encoder, txLen int) *big.Int {
fee := new(big.Int)
txLenGasPerByte := new(big.Int)

txLenGasPerByte.Mul(utils.NewIntFromUint64(uint64(txLen)), &Config.Client.GasPerByte)
fee.Add(&Config.Client.BaseGas, txLenGasPerByte)
fee.Mul(fee, &Config.Client.GasPrice)
txLenGasPerByte.Mul(utils.NewIntFromUint64(uint64(txLen)), Config.Client.GasPerByte)
fee.Add(Config.Client.BaseGas, txLenGasPerByte)
fee.Mul(fee, Config.Client.GasPrice)
return fee
}

Expand All @@ -177,14 +177,14 @@ func calcFeeContract(gas *big.Int, baseGasMultiplier int64, length int) *big.Int
txLenBig := new(big.Int)
answer := new(big.Int)

baseGas5.Mul(&Config.Client.BaseGas, big.NewInt(baseGasMultiplier))
baseGas5.Mul(Config.Client.BaseGas, big.NewInt(baseGasMultiplier))
txLenBig.SetUint64(uint64(length))
txLenGasPerByte := new(big.Int)
txLenGasPerByte.Mul(txLenBig, &Config.Client.GasPerByte)
txLenGasPerByte.Mul(txLenBig, Config.Client.GasPerByte)

answer.Add(baseGas5, gas)
answer.Add(answer, txLenGasPerByte)
answer.Mul(answer, &Config.Client.GasPrice)
answer.Mul(answer, Config.Client.GasPrice)
return answer
}

Expand Down
4 changes: 2 additions & 2 deletions aeternity/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestSignedTx(t *testing.T) {
Tx: &SpendTx{
SenderID: "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi",
RecipientID: "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v",
Amount: *utils.NewIntFromUint64(10),
Fee: *utils.NewIntFromUint64(10),
Amount: utils.NewIntFromUint64(10),
Fee: utils.NewIntFromUint64(10),
Payload: []byte("Hello World"),
TTL: uint64(10),
Nonce: uint64(1),
Expand Down

0 comments on commit 1311831

Please sign in to comment.