Skip to content

Commit

Permalink
refactor: Oracle*Tx constructors now do the work of Context
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Nov 11, 2019
1 parent 40f5481 commit f549966
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 56 deletions.
48 changes: 0 additions & 48 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,54 +90,6 @@ func NewContextFromNode(node *naet.Node, address string) (ctx *Context) {
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 *transactions.OracleRegisterTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = transactions.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 *transactions.OracleExtendTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = transactions.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 *transactions.OracleQueryTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = transactions.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 *transactions.OracleRespondTx, err error) {
ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL)
if err != nil {
return
}

tx = transactions.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 *transactions.ContractCreateTx, err error) {
Expand Down
45 changes: 37 additions & 8 deletions transactions/tx_oracles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"

"github.com/aeternity/aepp-sdk-go/v6/binary"
"github.com/aeternity/aepp-sdk-go/v6/config"
"github.com/aeternity/aepp-sdk-go/v6/swagguard/node/models"
"github.com/aeternity/aepp-sdk-go/v6/utils"
rlp "github.com/randomshinichi/rlpae"
Expand Down Expand Up @@ -159,8 +160,15 @@ func (tx *OracleRegisterTx) GetGasLimit() *big.Int {
}

// NewOracleRegisterTx is a constructor for a OracleRegisterTx struct
func NewOracleRegisterTx(accountID string, accountNonce uint64, querySpec, responseSpec string, queryFee *big.Int, oracleTTLType, oracleTTLValue uint64, abiVersion uint16, txFee *big.Int, txTTL uint64) *OracleRegisterTx {
return &OracleRegisterTx{accountID, accountNonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, abiVersion, txFee, txTTL}
func NewOracleRegisterTx(accountID string, querySpec, responseSpec string, queryFee *big.Int, oracleTTLType, oracleTTLValue uint64, abiVersion uint16, ttlnoncer TTLNoncer) (tx *OracleRegisterTx, err error) {
ttl, accountNonce, err := ttlnoncer(accountID, config.Client.TTL)
if err != nil {
return
}

tx = &OracleRegisterTx{accountID, accountNonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, abiVersion, config.Client.Fee, ttl}
CalculateFee(tx)
return
}

// OracleExtendTx represents a transaction that extends the lifetime of an oracle
Expand Down Expand Up @@ -275,8 +283,15 @@ func (tx *OracleExtendTx) GetGasLimit() *big.Int {
}

// NewOracleExtendTx is a constructor for a OracleExtendTx struct
func NewOracleExtendTx(oracleID string, accountNonce, oracleTTLType, oracleTTLValue uint64, Fee *big.Int, TTL uint64) *OracleExtendTx {
return &OracleExtendTx{oracleID, accountNonce, oracleTTLType, oracleTTLValue, Fee, TTL}
func NewOracleExtendTx(oracleID string, accountNonce, oracleTTLType, oracleTTLValue uint64, ttlnoncer TTLNoncer) (tx *OracleExtendTx, err error) {
ttl, accountNonce, err := ttlnoncer(oracleID, config.Client.TTL)
if err != nil {
return
}

tx = &OracleExtendTx{oracleID, accountNonce, oracleTTLType, oracleTTLValue, config.Client.Fee, ttl}
CalculateFee(tx)
return
}

// OracleQueryTx represents a transaction that a program sends to query an oracle
Expand Down Expand Up @@ -427,8 +442,15 @@ func (tx *OracleQueryTx) GetGasLimit() *big.Int {
}

// NewOracleQueryTx is a constructor for a OracleQueryTx struct
func NewOracleQueryTx(SenderID string, AccountNonce uint64, OracleID, Query string, QueryFee *big.Int, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64, Fee *big.Int, TTL uint64) *OracleQueryTx {
return &OracleQueryTx{SenderID, AccountNonce, OracleID, Query, QueryFee, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue, Fee, TTL}
func NewOracleQueryTx(senderID string, oracleID, query string, queryFee *big.Int, queryTTLType, queryTTLValue, responseTTLType, responseTTLValue uint64, ttlnoncer TTLNoncer) (tx *OracleQueryTx, err error) {
ttl, accountNonce, err := ttlnoncer(senderID, config.Client.TTL)
if err != nil {
return
}

tx = &OracleQueryTx{senderID, accountNonce, oracleID, query, queryFee, queryTTLType, queryTTLValue, responseTTLType, responseTTLValue, config.Client.Fee, ttl}
CalculateFee(tx)
return
}

// OracleRespondTx represents a transaction that an oracle sends to respond to an incoming query
Expand Down Expand Up @@ -560,6 +582,13 @@ func (tx *OracleRespondTx) GetGasLimit() *big.Int {
}

// NewOracleRespondTx is a constructor for a OracleRespondTx struct
func NewOracleRespondTx(OracleID string, AccountNonce uint64, QueryID string, Response string, TTLType uint64, TTLValue uint64, Fee *big.Int, TTL uint64) *OracleRespondTx {
return &OracleRespondTx{OracleID, AccountNonce, QueryID, Response, TTLType, TTLValue, Fee, TTL}
func NewOracleRespondTx(oracleID string, queryID string, response string, responseTTLType uint64, responseTTLValue uint64, ttlnoncer TTLNoncer) (tx *OracleRespondTx, err error) {
ttl, accountNonce, err := ttlnoncer(oracleID, config.Client.TTL)
if err != nil {
return
}

tx = &OracleRespondTx{oracleID, accountNonce, queryID, response, responseTTLType, responseTTLValue, config.Client.Fee, ttl}
CalculateFee(tx)
return
}

0 comments on commit f549966

Please sign in to comment.