Skip to content

Commit

Permalink
refactor: Contract{} helper struct does not need to know the Account.…
Browse files Browse the repository at this point in the history
… It just needs a ak_ public key. In fact many helper structs should be refactored this way in the future.
  • Loading branch information
randomshinichi committed Jul 4, 2019
1 parent 5c1a91e commit 1a4cb39
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,23 @@ func (o *Oracle) OracleRespondTx(OracleID string, QueryID string, Response strin

// ContractCreateTx returns a transaction for creating a contract on the chain
func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint16, Deposit, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCreateTx, err error) {
ttl, nonce, err := GetTTLNonce(c.Client, c.Account.Address, Config.Client.TTL)
ttl, nonce, err := GetTTLNonce(c.Client, c.Owner, Config.Client.TTL)
if err != nil {
return ContractCreateTx{}, err
}

tx = NewContractCreateTx(c.Account.Address, nonce, Code, VMVersion, AbiVersion, Deposit, Amount, Gas, GasPrice, Fee, ttl, CallData)
tx = NewContractCreateTx(c.Owner, nonce, Code, VMVersion, AbiVersion, Deposit, Amount, Gas, GasPrice, Fee, ttl, CallData)
return tx, nil
}

// ContractCallTx returns a transaction for calling a contract on the chain
func (c *Contract) ContractCallTx(ContractID, CallData string, AbiVersion uint16, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCallTx, err error) {
ttl, nonce, err := GetTTLNonce(c.Client, c.Account.Address, Config.Client.TTL)
ttl, nonce, err := GetTTLNonce(c.Client, c.Owner, Config.Client.TTL)
if err != nil {
return ContractCallTx{}, err
}

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

Expand Down
3 changes: 1 addition & 2 deletions aeternity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ type Aens struct {
type Contract struct {
Client *Client
Compiler *Compiler
Account *Account
source string
Owner string
}

// Oracle is a account-specific helper that stores state relevant to oracles
Expand Down
2 changes: 1 addition & 1 deletion integration_test/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestContracts(t *testing.T) {
alice, _ := setupAccounts(t)
aeClient := setupNetwork(t, privatenetURL)
contractsAlice := aeternity.Contract{Client: aeClient, Account: alice}
contractsAlice := aeternity.Contract{Client: aeClient, Owner: alice.Address}

var ctID string
var callData string
Expand Down

0 comments on commit 1a4cb39

Please sign in to comment.