From c6f9a76df6efcf6e177575e534edbffa82744191 Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Wed, 17 Jun 2020 17:29:52 +1000 Subject: [PATCH] Remove OracleNodeAPI wrapper --- es/ae/oracle.js | 10 ++-- es/chain/index.js | 4 +- es/chain/node.js | 3 +- es/index.js | 2 - es/oracle/index.js | 82 --------------------------------- es/oracle/node.js | 49 -------------------- test/integration/transaction.js | 10 ++-- 7 files changed, 13 insertions(+), 147 deletions(-) delete mode 100644 es/oracle/index.js delete mode 100644 es/oracle/node.js diff --git a/es/ae/oracle.js b/es/ae/oracle.js index 385dbeb952..84b38c7fe4 100644 --- a/es/ae/oracle.js +++ b/es/ae/oracle.js @@ -44,8 +44,8 @@ import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/sc * @return {Promise} 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, @@ -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) @@ -95,7 +95,7 @@ function pollForQueries (oracleId, onQuery, { interval = 5000 } = {}) { * @return {Promise} 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(), @@ -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 diff --git a/es/chain/index.js b/es/chain/index.js index 2944cb345d..7dbdd62137 100644 --- a/es/chain/index.js +++ b/es/chain/index.js @@ -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' /** @@ -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({ diff --git a/es/chain/node.js b/es/chain/node.js index 8753efb985..1a2afdf643 100644 --- a/es/chain/node.js +++ b/es/chain/node.js @@ -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' @@ -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 }, diff --git a/es/index.js b/es/index.js index 93df6fcb1c..c621bfc6b5 100644 --- a/es/index.js +++ b/es/index.js @@ -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' @@ -75,7 +74,6 @@ export { Node, NodePool, Oracle, - OracleNodeAPI, Selector, Transaction, TransactionValidator, diff --git a/es/oracle/index.js b/es/oracle/index.js deleted file mode 100644 index cf790fc964..0000000000 --- a/es/oracle/index.js +++ /dev/null @@ -1,82 +0,0 @@ -/* - * ISC License (ISC) - * Copyright (c) 2018 aeternity developers - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/** - * Oracle Base module - * @module @aeternity/aepp-sdk/es/oracle - * @export Contract - * @example import ContractBase from '@aeternity/aepp-sdk/es/oracle' - */ - -import { required } from '@stamp/required' -import stampit from '@stamp/it' - -/** - * Basic Oracle Stamp - * - * This stamp include api call's related to oracle functionality. - * Attempting to create instances from the Stamp without overwriting all - * abstract methods using composition will result in an exception. - * @function - * @alias module:@aeternity/aepp-sdk/es/oracle - * @rtype Stamp - * @param {Object} [options={}] - Initializer object - * @return {Object} Oracle instance - */ -const OracleBase = stampit(required({ - methods: { - getOracle: required, - getOracleQueries: required, - getOracleQuery: required - } -})) - -/** - * Get oracle by oracle public key - * @function getOracle - * @instance - * @abstract - * @category async - * @rtype (oracleId: String) => oracle: Promise[Object] - * @param {String} oracleId - Oracle public key - * @return {Object} - Oracle object - */ - -/** - * Get oracle queries - * @function getOracleQueries - * @instance - * @abstract - * @category async - * @rtype (oracleId: String) => oracleQueries: Promise[Object] - * @param {String} oracleId- Oracle public key - * @return {Object} - Oracle queries - */ - -/** - * Get oracle query - * @function getOracleQuery - * @instance - * @abstract - * @category async - * @rtype (oracleId: String, queryId: String) => oracleQuery: Promise[Object] - * @param {String} oracleId - Oracle public key - * @param {String} queryId - Query id - * @return {Object} - Oracle query object - */ - -export default OracleBase diff --git a/es/oracle/node.js b/es/oracle/node.js deleted file mode 100644 index 86a4675868..0000000000 --- a/es/oracle/node.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ISC License (ISC) - * Copyright (c) 2018 aeternity developers - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/** - * OracleNodeAPI module - * - * This is the complement to {@link module:@aeternity/aepp-sdk/es/oracle}. - * @module @aeternity/aepp-sdk/es/oracle/node - * @export OracleNodeAPI - * @example import OracleNodeAPI from '@aeternity/aepp-sdk/es/oracle/node' - */ - -import OracleBase from './' - -async function getOracle (oracleId) { - return this.api.getOracleByPubkey(oracleId) -} - -async function getOracleQueries (oracleId) { - return this.api.getOracleQueriesByPubkey(oracleId) -} - -async function getOracleQuery (oracleId, queryId) { - return this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId) -} - -const OracleNodeAPI = OracleBase.compose({ - methods: { - getOracle, - getOracleQueries, - getOracleQuery - } -}) - -export default OracleNodeAPI diff --git a/test/integration/transaction.js b/test/integration/transaction.js index 1d6ea2e079..caede8921f 100644 --- a/test/integration/transaction.js +++ b/test/integration/transaction.js @@ -201,14 +201,14 @@ 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) @@ -216,7 +216,7 @@ describe('Native Transaction', function () { 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) }) @@ -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) }) @@ -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 () => {