Skip to content

Commit

Permalink
feature: tx structs, unittests, helpers, config, api updated to suppo…
Browse files Browse the repository at this point in the history
…rt v3.0.1 types
  • Loading branch information
randomshinichi committed Jun 6, 2019
1 parent 63844f9 commit e90ecfc
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 107 deletions.
6 changes: 3 additions & 3 deletions aeternity/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (ae *Client) APIPostTransaction(signedEncodedTx, signedEncodedTxHash string
// postTransaction post a transaction to the chain
func postTransaction(node *Client, signedEncodedTx, signedEncodedTxHash string) (err error) {
p := external.NewPostTransactionParams().WithBody(&models.Tx{
Tx: &signedEncodedTx,
Tx: models.EncodedByteArray(signedEncodedTx),
})
r, err := node.External.PostTransaction(p)
if err != nil {
Expand All @@ -56,10 +56,10 @@ func (ae *Client) APIGetHeight() (height uint64, err error) {
return
}
if tb.KeyBlock == nil {
height = *tb.MicroBlock.Height
height = uint64(tb.MicroBlock.Height)
return
}
height = *tb.KeyBlock.Height
height = uint64(tb.KeyBlock.Height)
return
}

Expand Down
4 changes: 2 additions & 2 deletions aeternity/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ContractConfig struct {
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"`
Deposit big.Int `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"`
}
Expand Down Expand Up @@ -114,7 +114,7 @@ var Config = ProfileConfig{
Gas: *utils.NewIntFromUint64(1e9),
GasPrice: *utils.NewIntFromUint64(1e9),
Amount: *new(big.Int),
Deposit: 0,
Deposit: *new(big.Int),
VMVersion: 3,
ABIVersion: 1,
},
Expand Down
27 changes: 14 additions & 13 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func getTTL(node *Client, offset uint64) (height uint64, err error) {
}

if kb.KeyBlock == nil {
height = *kb.MicroBlock.Height + offset
height = uint64(kb.MicroBlock.Height) + offset
} else {
height = *kb.KeyBlock.Height + offset
height = uint64(kb.KeyBlock.Height) + offset
}

return
Expand All @@ -45,7 +45,7 @@ func getNextNonce(node *Client, accountID string) (nextNonce uint64, err error)
if err != nil {
return
}
nextNonce = *a.Nonce + 1
nextNonce = uint64(a.Nonce) + 1
return
}

Expand Down Expand Up @@ -79,7 +79,8 @@ func waitForTransaction(nodeClient *Client, txHash string) (blockHeight uint64,
break
}
if len(tx.BlockHash) > 0 {
blockHeight = *tx.BlockHeight
txbh := big.Int(tx.BlockHeight)
blockHeight = txbh.Uint64()
blockHash = fmt.Sprint(tx.BlockHash)
break
}
Expand Down Expand Up @@ -152,8 +153,8 @@ func (client *Client) WaitForTransactionUntilHeight(height uint64, txHash string
return
}
// current height
targetHeight := *kb.Height
nextHeight := *kb.Height
targetHeight := uint64(kb.Height)
nextHeight := uint64(kb.Height)
// hold the generation
var g *models.Generation

Expand Down Expand Up @@ -187,7 +188,7 @@ Main:
if fmt.Sprint(btx.Hash) == txHash {
// transaction found !!
blockHash = fmt.Sprint(g.KeyBlock.Hash)
blockHeight = *g.KeyBlock.Height
blockHeight = uint64(g.KeyBlock.Height)
microBlockHash = mbhs
tx = btx
break Main
Expand All @@ -205,7 +206,7 @@ Main:
if err != nil {
break
}
nextHeight = *kb.Height
nextHeight = uint64(kb.Height)
}

return
Expand Down Expand Up @@ -298,13 +299,13 @@ func (n *Aens) NameRevokeTx(name string, recipientAddress string) (tx NameRevoke
}

// OracleRegisterTx create a new oracle
func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee big.Int, oracleTTLType, oracleTTLValue, abiVersion uint64, vmVersion uint64) (tx OracleRegisterTx, err error) {
func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee big.Int, oracleTTLType, oracleTTLValue, abiVersion uint64) (tx OracleRegisterTx, err error) {
ttl, nonce, err := getTTLNonce(o.Client, o.Account.Address, Config.Client.TTL)
if err != nil {
return OracleRegisterTx{}, err
}

tx = NewOracleRegisterTx(o.Account.Address, nonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, abiVersion, vmVersion, Config.Client.Fee, ttl)
tx = NewOracleRegisterTx(o.Account.Address, nonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, abiVersion, Config.Client.Fee, ttl)
return tx, nil
}

Expand Down Expand Up @@ -341,7 +342,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 big.Int) (tx ContractCreateTx, err error) {
func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint64, Deposit, 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,13 +352,13 @@ 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 big.Int) (tx ContractCallTx, err error) {
func (c *Contract) ContractCallTx(ContractID, CallData string, 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
}

tx = NewContractCallTx(c.Account.Address, nonce, ContractID, Amount, Gas, GasPrice, AbiVersion, VMVersion, CallData, Fee, ttl)
tx = NewContractCallTx(c.Account.Address, nonce, ContractID, Amount, Gas, GasPrice, AbiVersion, CallData, Fee, ttl)
return tx, nil
}

Expand Down

0 comments on commit e90ecfc

Please sign in to comment.