Skip to content

Commit

Permalink
feat: OracleRegisterTx, OracleExtendTx. Incomplete unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Mar 26, 2019
1 parent a0325fc commit 7c7dbcb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
43 changes: 31 additions & 12 deletions aeternity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func createSignedTransaction(txRaw []byte, signatures [][]byte) (rlpRawMsg []byt
}

// SpendTx create a spend transaction
// see https://github.com/aeternity/protocol/blob/epoch-v0.22.0/serializations.md
func SpendTx(senderID, recipientID string, amount, fee utils.BigInt, payload string, ttl, nonce uint64) (rlpRawMsg []byte, err error) {
// build id for the sender
sID, err := buildIDTag(IDTagAccount, senderID)
Expand All @@ -66,7 +65,6 @@ func SpendTx(senderID, recipientID string, amount, fee utils.BigInt, payload str
}

// NamePreclaimTx build a preclaim transaction
// see https://github.com/aeternity/protocol/blob/epoch-v0.22.0/serializations.md#name-service-preclaim-transaction
func NamePreclaimTx(accountID, commitmentID string, fee uint64, ttl, nonce uint64) (rlpRawMsg []byte, err error) {
// build id for the sender
aID, err := buildIDTag(IDTagAccount, accountID)
Expand All @@ -91,7 +89,6 @@ func NamePreclaimTx(accountID, commitmentID string, fee uint64, ttl, nonce uint6
}

// NameClaimTx build a preclaim transaction
// see https://github.com/aeternity/protocol/blob/epoch-v0.22.0/serializations.md#name-service-claim-transaction
func NameClaimTx(accountID, name string, nameSalt, fee uint64, ttl, nonce uint64) (rlpRawMsg []byte, err error) {
// build id for the sender
aID, err := buildIDTag(IDTagAccount, accountID)
Expand Down Expand Up @@ -141,7 +138,6 @@ func buildPointers(pointers []string) (ptrs [][]uint8, err error) {
}

// NameUpdateTx build an update name transaction
// see https://github.com/aeternity/protocol/blob/epoch-v0.22.0/serializations.md#name-service-update-transaction
func NameUpdateTx(accountID, nameID string, pointers []string, nameTTL, clientTTL uint64, fee uint64, ttl, nonce uint64) (rlpRawMsg []byte, err error) {
// build id for the sender
aID, err := buildIDTag(IDTagAccount, accountID)
Expand Down Expand Up @@ -174,22 +170,45 @@ func NameUpdateTx(accountID, nameID string, pointers []string, nameTTL, clientTT
return
}

// OracleRegisterTx register an oracle tx
// see https://github.com/aeternity/protocol/blob/master/serializations.md#oracles
func OracleRegisterTx(accountID, queryFormat, responseFormat string, queryFee, expires int64) (rlpRawMsg []byte, err error) {
// OracleRegisterTx register an oracle
func OracleRegisterTx(accountID string, accountNonce uint64, querySpec, responseSpec string, queryFee uint64, ttlType string, ttlValue uint64, fee utils.BigInt, ttl, abiVersion uint64) (rlpRawMsg []byte, err error) {
// build id for the account
aID, err := buildIDTag(IDTagAccount, accountID)
if err != nil {
return
}
// create the transaction
rlpRawMsg, err = buildRLPMessage(
ObjectTagOracle,
ObjectTagOracleRegisterTransaction,
rlpMessageVersion,
aID,
[]byte(queryFormat),
[]byte(responseFormat),
uint64(queryFee),
uint64(expires))
accountNonce,
[]byte(querySpec),
[]byte(responseSpec),
queryFee,
[]byte(ttlType),
ttlValue,
fee.Bytes(),
ttl,
abiVersion)
return
}

// OracleExtendTx extend an oracle's lifetime
func OracleExtendTx(oracleID string, accountNonce, ttlType, ttlValue uint64, fee utils.BigInt, ttl uint64) (rlpRawMsg []byte, err error) {
aID, err := buildIDTag(IDTagOracle, oracleID)
if err != nil {
return
}

rlpRawMsg, err = buildRLPMessage(
ObjectTagOracleExtendTransaction,
rlpMessageVersion,
aID,
accountNonce,
ttlType,
ttlValue,
fee.Bytes(),
ttl)
return
}
20 changes: 20 additions & 0 deletions aeternity/transactions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package aeternity_test

import (
"fmt"
"testing"

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

func TestOracleRegisterTx(t *testing.T) {
sender := "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi"
fee := utils.NewBigIntFromUint64(100)
txRaw, err := aeternity.OracleRegisterTx(sender, 0, "likethis", "likethat", 123456789, "delta", 1, *fee, 1, 1)
if err != nil {
t.Errorf("Could not create OracleRegisterTx: %s", err)
}
txStr := aeternity.Encode(aeternity.PrefixTransaction, txRaw)
fmt.Println(txStr)
}

0 comments on commit 7c7dbcb

Please sign in to comment.