Skip to content

Commit

Permalink
Remove OracleNodeAPI wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Mar 1, 2021
1 parent c856244 commit c6f9a76
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 147 deletions.
10 changes: 5 additions & 5 deletions es/ae/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/sc
* @return {Promise<Object>} Oracle object
*/
async function getOracleObject (oracleId) {
const oracle = await this.getOracle(oracleId)
const { oracleQueries: queries } = await this.getOracleQueries(oracleId)
const oracle = await this.api.getOracleByPubkey(oracleId)
const { oracleQueries: queries } = await this.api.getOracleQueriesByPubkey(oracleId)
return {
...oracle,
queries,
Expand All @@ -72,7 +72,7 @@ async function getOracleObject (oracleId) {
function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) {
const knownQueryIds = new Set()
const checkNewQueries = async () => {
const queries = ((await this.getOracleQueries(oracleId)).oracleQueries || [])
const queries = ((await this.api.getOracleQueriesByPubkey(oracleId)).oracleQueries || [])
.filter(({ id }) => !knownQueryIds.has(id))
queries.forEach(({ id }) => knownQueryIds.add(id))
if (queries.length) onQuery(queries)
Expand All @@ -95,7 +95,7 @@ function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) {
* @return {Promise<Object>} OracleQuery object
*/
async function getQueryObject (oracleId, queryId) {
const q = await this.getOracleQuery(oracleId, queryId)
const q = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
return {
...q,
decodedQuery: decodeBase64Check(q.query.slice(3)).toString(),
Expand All @@ -122,7 +122,7 @@ async function getQueryObject (oracleId, queryId) {
export async function pollForQueryResponse (oracleId, queryId, { attempts = 20, interval = 5000 } = {}) {
for (let i = 0; i < attempts; i++) {
if (i) await pause(interval)
const { response } = await this.getOracleQuery(oracleId, queryId)
const { response } = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
const responseBuffer = decodeBase64Check(assertedType(response, 'or'))
if (responseBuffer.length) {
return { response, decode: () => responseBuffer } // TODO: Return just responseBuffer
Expand Down
4 changes: 2 additions & 2 deletions es/chain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @example import Chain from '@aeternity/aepp-sdk/es/chain'
*/

import Oracle from '../oracle'
import stampit from '@stamp/it'
import { required } from '@stamp/required'

/**
Expand All @@ -36,7 +36,7 @@ import { required } from '@stamp/required'
* @param {Object} [options={}] - Initializer object
* @return {Object} Chain instance
*/
const Chain = Oracle.compose({
const Chain = stampit({
deepProps: { Ae: { defaults: { waitMined: true } } },
statics: { waitMined (bool) { return this.deepProps({ Ae: { defaults: { waitMined: bool } } }) } }
}, required({
Expand Down
3 changes: 1 addition & 2 deletions es/chain/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import * as R from 'ramda'

import Chain from './'
import Oracle from '../oracle/node'
import { AE_AMOUNT_FORMATS, formatAmount } from '../utils/amount-formatter'
import TransactionValidator from '../tx/validator'
import NodePool from '../node-pool'
Expand Down Expand Up @@ -229,7 +228,7 @@ async function resolveName (nameOrId, prefix, { verify = false, resolveByNode =
* @return {Object} ChainNode instance
* @example ChainNode({url: 'https://testnet.aeternity.io/'})
*/
const ChainNode = Chain.compose(Oracle, TransactionValidator, NodePool, {
const ChainNode = Chain.compose(TransactionValidator, NodePool, {
init ({ verifyTx = true }) {
this.verifyTxBeforeSend = verifyTx
},
Expand Down
2 changes: 0 additions & 2 deletions es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import ContractCompilerAPI from './contract/compiler'
import RpcAepp from './ae/aepp'
import RpcWallet from './ae/wallet'
import Oracle from './ae/oracle'
import OracleNodeAPI from './oracle/node'
import Selector from './account/selector'
import Channel from './channel'
import Universal from './ae/universal'
Expand Down Expand Up @@ -75,7 +74,6 @@ export {
Node,
NodePool,
Oracle,
OracleNodeAPI,
Selector,
Transaction,
TransactionValidator,
Expand Down
82 changes: 0 additions & 82 deletions es/oracle/index.js

This file was deleted.

49 changes: 0 additions & 49 deletions es/oracle/node.js

This file was deleted.

10 changes: 5 additions & 5 deletions test/integration/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,22 @@ describe('Native Transaction', function () {
txFromAPI.should.be.equal(nativeTx)
await clientNative.send(nativeTx, { verify: true })

const oId = (await client.getOracle(oracleId)).id
const oId = (await client.api.getOracleByPubkey(oracleId)).id
oId.should.be.equal(oracleId)
})

it('native build of oracle extends tx', async () => {
const callerId = await client.address()
const params = { oracleId, callerId, oracleTtl }
const orTtl = (await client.getOracle(oracleId)).ttl
const orTtl = (await client.api.getOracleByPubkey(oracleId)).ttl

const txFromAPI = await client.oracleExtendTx(params)
const nativeTx = await clientNative.oracleExtendTx(params)

txFromAPI.should.be.equal(nativeTx)

await client.send(nativeTx)
const orNewTtl = (await client.getOracle(oracleId)).ttl
const orNewTtl = (await client.api.getOracleByPubkey(oracleId)).ttl
orNewTtl.should.be.equal(orTtl + oracleTtl.value)
})

Expand All @@ -233,7 +233,7 @@ describe('Native Transaction', function () {

await client.send(nativeTx)

const oracleQuery = (await client.getOracleQuery(oracleId, queryId))
const oracleQuery = (await client.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId))
oracleQuery.id.should.be.equal(queryId)
})

Expand All @@ -247,7 +247,7 @@ describe('Native Transaction', function () {

await client.send(nativeTx)

const orQuery = (await client.getOracleQuery(oracleId, queryId))
const orQuery = (await client.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId))
orQuery.response.should.be.equal(`or_${encodeBase64Check(queryResponse)}`)
})
it('Get next account nonce', async () => {
Expand Down

0 comments on commit c6f9a76

Please sign in to comment.