Skip to content

Commit

Permalink
refactor(node)!: drop internalUrl
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removed `internalUrl`
`Node` doesn't accepts and stores `internalUrl`, also internal endpoints are not available anymore.
If necessary, create a wrapper of internal API separately (using `genSwaggerClient`).

BREAKING CHANGE: removed `mempool` method
Create a wrapper of internal API by `genSwaggerClient` and use `getPendingTransactions` method
instead.

Reverts: 690db5b
  • Loading branch information
davidyuk committed Apr 22, 2022
1 parent d0936ea commit 8336673
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 180 deletions.
1 change: 0 additions & 1 deletion docs/contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ import { Wallet, Contract, MemoryAccount } from '@aeternity/aepp-sdk'
// make a "mixed flavor" containing Wallet and Contracts flavors
Wallet.compose(Contract)({
url: 'https://testnet.aeternity.io',
internalUrl: 'https://testnet.aeternity.io',
accounts: [MemoryAccount({keypair: {secretKey: account.priv, publicKey: account.pub}})],
address: account.pub,
onTx: true, // or a function to Guard the Rpc client
Expand Down
114 changes: 42 additions & 72 deletions docs/guides/low-vs-high-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ async function spend (amount, recipient) {
})

// builds an unsigned SpendTx using the debug endpoint of the node's API
const spendTxResponse = await aeSdk.api.postSpend({
sender_id: await aeSdk.address(),
recipient_id: recipient,
fee: 18000000000000, // you must provide enough fee
amount, // aettos
payload: 'using low-level api is funny'
const spendTx = await aeSdk.spendTx({
senderId: await aeSdk.address(),
recipientId: recipient,
fee: 18000000000000, // you must provide enough fee
amount, // aettos
payload: 'using low-level api is funny'
})

// sign the encoded transaction returned by the node
const signedTx = await aeSdk.signTransaction(spendTxResponse.tx)
const signedTx = await aeSdk.signTransaction(spendTx)

// broadcast the signed tx to the node
console.log(await aeSdk.api.postTransaction({tx: signedTx}))
Expand All @@ -70,70 +70,40 @@ Following functions are available with the low-level API right now:
console.log(aeSdk.api)
/*
{
getTopHeader: [Function (anonymous)],
getCurrentKeyBlock: [Function (anonymous)],
getCurrentKeyBlockHash: [Function (anonymous)],
getCurrentKeyBlockHeight: [Function (anonymous)],
getPendingKeyBlock: [Function (anonymous)],
getKeyBlockByHash: [Function (anonymous)],
getKeyBlockByHeight: [Function (anonymous)],
getMicroBlockHeaderByHash: [Function (anonymous)],
getMicroBlockTransactionsByHash: [Function (anonymous)],
getMicroBlockTransactionByHashAndIndex: [Function (anonymous)],
getMicroBlockTransactionsCountByHash: [Function (anonymous)],
getCurrentGeneration: [Function (anonymous)],
getGenerationByHash: [Function (anonymous)],
getGenerationByHeight: [Function (anonymous)],
getAccountByPubkey: [Function (anonymous)],
getAccountByPubkeyAndHeight: [Function (anonymous)],
getAccountByPubkeyAndHash: [Function (anonymous)],
getPendingAccountTransactionsByPubkey: [Function (anonymous)],
protectedDryRunTxs: [Function (anonymous)],
getTransactionByHash: [Function (anonymous)],
getTransactionInfoByHash: [Function (anonymous)],
postTransaction: [Function (anonymous)],
getContract: [Function (anonymous)],
getContractCode: [Function (anonymous)],
getContractPoI: [Function (anonymous)],
getOracleByPubkey: [Function (anonymous)],
getOracleQueriesByPubkey: [Function (anonymous)],
getOracleQueryByPubkeyAndQueryId: [Function (anonymous)],
getNameEntryByName: [Function (anonymous)],
getChannelByPubkey: [Function (anonymous)],
getPeerPubkey: [Function (anonymous)],
getStatus: [Function (anonymous)],
getChainEnds: [Function (anonymous)],
postKeyBlock: [Function (anonymous)],
postSpend: [Function (anonymous)],
getPendingTransactions: [Function (anonymous)],
postPayingFor: [Function (anonymous)],
postContractCreate: [Function (anonymous)],
postContractCall: [Function (anonymous)],
postOracleRegister: [Function (anonymous)],
postOracleExtend: [Function (anonymous)],
postOracleQuery: [Function (anonymous)],
postOracleRespond: [Function (anonymous)],
postNamePreclaim: [Function (anonymous)],
postNameClaim: [Function (anonymous)],
postNameUpdate: [Function (anonymous)],
postNameTransfer: [Function (anonymous)],
postNameRevoke: [Function (anonymous)],
getCommitmentId: [Function (anonymous)],
postChannelCreate: [Function (anonymous)],
postChannelDeposit: [Function (anonymous)],
postChannelWithdraw: [Function (anonymous)],
postChannelSnapshotSolo: [Function (anonymous)],
postChannelSetDelegates: [Function (anonymous)],
postChannelCloseMutual: [Function (anonymous)],
postChannelCloseSolo: [Function (anonymous)],
postChannelSlash: [Function (anonymous)],
postChannelSettle: [Function (anonymous)],
getNetworkStatus: [Function (anonymous)],
getNodeBeneficiary: [Function (anonymous)],
getNodePubkey: [Function (anonymous)],
getPeers: [Function (anonymous)],
dryRunTxs: [Function (anonymous)],
getTokenSupplyByHeight: [Function (anonymous)]
getTopHeader: [AsyncFunction (anonymous)],
getCurrentKeyBlock: [AsyncFunction (anonymous)],
getCurrentKeyBlockHash: [AsyncFunction (anonymous)],
getCurrentKeyBlockHeight: [AsyncFunction (anonymous)],
getPendingKeyBlock: [AsyncFunction (anonymous)],
getKeyBlockByHash: [AsyncFunction (anonymous)],
getKeyBlockByHeight: [AsyncFunction (anonymous)],
getMicroBlockHeaderByHash: [AsyncFunction (anonymous)],
getMicroBlockTransactionsByHash: [AsyncFunction (anonymous)],
getMicroBlockTransactionByHashAndIndex: [AsyncFunction (anonymous)],
getMicroBlockTransactionsCountByHash: [AsyncFunction (anonymous)],
getCurrentGeneration: [AsyncFunction (anonymous)],
getGenerationByHash: [AsyncFunction (anonymous)],
getGenerationByHeight: [AsyncFunction (anonymous)],
getAccountByPubkey: [AsyncFunction (anonymous)],
getAccountByPubkeyAndHeight: [AsyncFunction (anonymous)],
getAccountByPubkeyAndHash: [AsyncFunction (anonymous)],
getPendingAccountTransactionsByPubkey: [AsyncFunction (anonymous)],
getAccountNextNonce: [AsyncFunction (anonymous)],
protectedDryRunTxs: [AsyncFunction (anonymous)],
getTransactionByHash: [AsyncFunction (anonymous)],
getTransactionInfoByHash: [AsyncFunction (anonymous)],
postTransaction: [AsyncFunction (anonymous)],
getContract: [AsyncFunction (anonymous)],
getContractCode: [AsyncFunction (anonymous)],
getContractPoI: [AsyncFunction (anonymous)],
getOracleByPubkey: [AsyncFunction (anonymous)],
getOracleQueriesByPubkey: [AsyncFunction (anonymous)],
getOracleQueryByPubkeyAndQueryId: [AsyncFunction (anonymous)],
getNameEntryByName: [AsyncFunction (anonymous)],
getChannelByPubkey: [AsyncFunction (anonymous)],
getPeerPubkey: [AsyncFunction (anonymous)],
getStatus: [AsyncFunction (anonymous)],
getChainEnds: [AsyncFunction (anonymous)]
}
*/
```
```
4 changes: 2 additions & 2 deletions src/ae/contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ISC License (ISC)
* Copyright (c) 2021 aeternity developers
* Copyright (c) 2022 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
Expand Down Expand Up @@ -124,7 +124,7 @@ async function createOracleDelegationSignature ({ contractId, queryId }, opt = {
*
* const ContractWithAE = await Contract
* .compose(Transaction, MemoryAccount, ChainNode) // AE implementation
* const client = await ContractWithAe({ url, internalUrl, compilerUrl, keypair, ... })
* const client = await ContractWithAe({ url, compilerUrl, keypair, ... })
*
*/
export default Ae.compose(ContractCompilerHttp, {
Expand Down
13 changes: 1 addition & 12 deletions src/chain/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ISC License (ISC)
* Copyright (c) 2018 aeternity developers
* Copyright (c) 2022 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
Expand Down Expand Up @@ -68,7 +68,6 @@ const Chain = stampit({
getBalance: required,
tx: required,
getTxInfo: required,
mempool: required,
txDryRun: required,
getAccount: required
}
Expand Down Expand Up @@ -163,16 +162,6 @@ const Chain = stampit({
* @return {Object} Transaction
*/

/**
* Obtain transaction's from mempool
* @function mempool
* @instance
* @abstract
* @category async
* @rtype () => txs: [...Object]
* @return {Object[]} Transactions
*/

/**
* Obtain current generation
* @function getCurrentGeneration
Expand Down
10 changes: 2 additions & 8 deletions src/chain/node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ISC License (ISC)
* Copyright (c) 2018 aeternity developers
* Copyright (c) 2022 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
Expand Down Expand Up @@ -152,8 +152,7 @@ async function poll (th, { blocks = 10, interval = this._getPollInterval('microb
if (tx.blockHeight !== -1) return tx
await pause(interval)
} while (await this.height() < max)
const status = this.api.getCheckTxInPool && (await this.api.getCheckTxInPool(th)).status
throw new TxTimedOutError(blocks, th, status)
throw new TxTimedOutError(blocks, th)
}

/**
Expand All @@ -164,10 +163,6 @@ async function getTxInfo (hash) {
return result.callInfo || result
}

async function mempool () {
return this.api.getPendingTransactions()
}

async function getCurrentGeneration () {
return this.api.getCurrentGeneration()
}
Expand Down Expand Up @@ -302,7 +297,6 @@ const ChainNode = Chain.compose(NodePool, {
awaitHeight,
poll,
getTxInfo,
mempool,
getCurrentGeneration,
getGeneration,
getMicroBlockHeader,
Expand Down
3 changes: 1 addition & 2 deletions src/node-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default stampit({
* @return {void}
* @example
* // add and select new node with name 'testNode'
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
* nodePool.addNode('testNode', awaitNode({ url }), true)
*/
addNode (name, node, select = false) {
if (this.pool.has(name)) throw new DuplicateNodeError(name)
Expand All @@ -64,7 +64,6 @@ export default stampit({
name,
instance: node,
url: node.url,
internalUrl: node.internalUrl,
networkId: node.nodeNetworkId,
version: node.version,
consensusProtocolVersion: node.consensusProtocolVersion
Expand Down
8 changes: 2 additions & 6 deletions src/node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ISC License (ISC)
* Copyright (c) 2021 aeternity developers
* Copyright (c) 2022 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
Expand Down Expand Up @@ -48,20 +48,17 @@ export function getNetworkId ({ networkId, force = false } = {}) {
* @rtype Stamp
* @param {Object} [options={}] - Options
* @param {String} options.url - Base URL for Node
* @param {String} options.internalUrl - Base URL for internal requests
* @param {Object} options.axiosConfig - Object with axios configuration
* @param {Object} options.axiosConfig.config
* @param {Function} options.axiosConfig.errorHandler - (err) => throw err
* @return {Object} Node client
* @example Node({url: 'https://testnet.aeternity.io'})
*/
const Node = AsyncInit.compose({
async init ({ url, internalUrl, ignoreVersion }) {
async init ({ url, ignoreVersion }) {
if (!url) throw new MissingParamError('"url" required')
this.url = url.replace(/\/$/, '')
this.internalUrl = internalUrl?.replace(/\/$/, '')
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
internalUrl: this.internalUrl,
responseInterceptor: response => {
if (response.ok) return
return Object.assign(response, {
Expand Down Expand Up @@ -96,7 +93,6 @@ const Node = AsyncInit.compose({
getNodeInfo () {
return {
url: this.url,
internalUrl: this.internalUrl,
nodeNetworkId: this.nodeNetworkId,
version: this.version,
consensusProtocolVersion: this.consensusProtocolVersion
Expand Down
3 changes: 1 addition & 2 deletions src/tx/tx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ISC License (ISC)
* Copyright (c) 2018 aeternity developers
* Copyright (c) 2022 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
Expand Down Expand Up @@ -363,7 +363,6 @@ async function prepareTxParams (
* @rtype Stamp
* @param {Object} [options={}] - Initializer object
* @param {String} options.url - Node url
* @param {String} options.internalUrl - Node internal url
* @return {Object} Transaction instance
* @example Transaction({url: 'https://testnet.aeternity.io/'})
*/
Expand Down
5 changes: 2 additions & 3 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ export class RequestTimedOutError extends BaseError {
}

export class TxTimedOutError extends BaseError {
constructor (blocks: number, th: string, status?: string) {
constructor (blocks: number, th: string) {
super([
`Giving up after ${blocks} blocks mined`,
`transaction hash: ${th}`,
...status != null ? [`status: ${status}`] : []
`transaction hash: ${th}`
].join(', '))
this.name = 'TxTimedOutError'
}
Expand Down
Loading

0 comments on commit 8336673

Please sign in to comment.