Skip to content

Commit

Permalink
Merge pull request #14 from Crypto-APIs/CRYPTOAPIS-2387
Browse files Browse the repository at this point in the history
#CRYPTOAPIS-2387
  • Loading branch information
Crypto-APIs authored Mar 10, 2020
2 parents c493f9e + f37aed5 commit c660ab8
Show file tree
Hide file tree
Showing 18 changed files with 322 additions and 7 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## 2020-03-10, Version 4.3.0

#### Added:
* Zilliqa (ZIL) - new blockchain (under development)
* `mainnet` only, `testnet` coming soon
* exposed endpoints so far:
* caClient.BC.ZIL.blockchain.getInfo
* caClient.BC.ZIL.blockchain.getBlockByHash
* caClient.BC.ZIL.blockchain.getBlockByHeight
* caClient.BC.ZIL.blockchain.getLatestBlock
* caClient.BC.ZIL.address.getInfo
* caClient.BC.ZIL.address.getTransactionsByAddress
* caClient.BC.ZIL.address.generateAddress
* caClient.BC.ZIL.transaction.getTransaction
* caClient.BC.ZIL.transaction.getTransactionsByBlock
* caClient.BC.ZIL.transaction.getTransactionByBlockNumber
* caClient.BC.ZIL.transaction.getTransactionByBlockHash
* XXX (BTC / BCH / LTC / DASH / DOGE)
* caClient.BC.XXX.address.getUnconfirmedByAddress
* caClient.BC.XXX.transaction.getTransactionSizeForHDWallet

## 2019-12-27, Version 4.2.2

#### Notable changes:
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ It will print the following:

## List of all methods available
NOTES:
* XXX - blockchain (BTC / BCH / LTC / DOGE / DASH / ETH / ETC)
* XXX - blockchain (BTC / BCH / LTC / DOGE / DASH / ETH / ETC / ZIL)
* doc links target BTC / ETH in our documentation to avoid repetition. For other blockchains refer to the corresponding parts in our [documentation](https://docs.cryptoapis.io/)

### BTC / BCH / LTC / DOGE / DASH methods
Expand All @@ -90,6 +90,7 @@ NOTES:
* caClient.BC.XXX.address.generateAddress ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-address-generate-address-endpoint))
* caClient.BC.XXX.address.getAddressTransactions ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-address-transactions-endpoint))
* caClient.BC.XXX.address.multipleAddressesInfo ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-multiple-addresses-info-endpoint))
* caClient.BC.XXX.address.getUnconfirmedByAddress ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-address-unconfirmed-transactions-endpoint))

#### Wallets methods
* caClient.BC.XXX.wallet.createWallet ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-wallet-create-wallet-endpoint))
Expand Down Expand Up @@ -122,6 +123,7 @@ NOTES:
* caClient.BC.XXX.transaction.getTransactionsFee ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-transactions-fee-endpoint))
* caClient.BC.XXX.transaction.getTransactionSize ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-transactions-size))
* caClient.BC.XXX.transaction.refund ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-refund-transaction))
* caClient.BC.XXX.transaction.getTransactionSizeForHDWallet ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-hd-wallet-transactions-size))

#### Payment Forwarding methods
* caClient.BC.XXX.paymentForwarding.createPaymentForwarding ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index#btc-payment-forwarding-create-payment-endpoint))
Expand Down Expand Up @@ -218,6 +220,26 @@ NOTES:
* caClient.BC.XXX.webhook.deleteAllMyWebhooks ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/eth/index#eth-delete-all-webhooks-endpoints))


### ZIL methods

#### Blockchain methods
* caClient.BC.XXX.blockchain.getInfo ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-chain-endpoint))
* caClient.BC.XXX.blockchain.getBlockByHash ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-block-hash-endpoint))
* caClient.BC.XXX.blockchain.getBlockByHeight ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-block-height-endpoint))
* caClient.BC.XXX.blockchain.getLatestBlock ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-latest-block-endpoint))

#### Addresses methods
* caClient.BC.XXX.address.getInfo ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-address-endpoint))
* caClient.BC.XXX.address.getTransactionsByAddress ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-transactions-address-endpoint))
* caClient.BC.XXX.address.generateAddress ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-generate-address-endpoint))

#### Transaction methods
* caClient.BC.XXX.transaction.getTransaction ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-transaction-hash-endpoint))
* caClient.BC.XXX.transaction.getTransactionsByBlock ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-transaction-index-endpoint-by-index-limit-block-number))
* caClient.BC.XXX.transaction.getTransactionByBlockNumber ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-transaction-index-endpoint-by-block-number))
* caClient.BC.XXX.transaction.getTransactionByBlockHash ([docs](https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/zil/index#zil-transaction-index-endpoint-by-block-hash))


# Crypto Market Data APIs

#### Metadata
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cryptoapis.io",
"version": "4.2.3",
"version": "4.3.0",
"description": "Crypto APIs SDK",
"main": "src/index.js",
"scripts": {
Expand All @@ -25,6 +25,7 @@
"cryptocurrency",
"coinmarketcap",
"coinapi",
"omni"
"omni",
"zil"
]
}
21 changes: 21 additions & 0 deletions src/common/blockchain/base-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ class BaseAddress extends BaseChainComponent {
return this.request.get(this.basePath + this.getSelectedNetwork() + '/address/' + address + '/transactions', combinedQueryParams);
}

/**
* Get Unconfirmed Transactions By Address
*
* @async
* @desc The Address Unconfirmed Transactions Endpoint returns all information available about a particular address, including an array of unconfirmed transactions.
*
* @param {string} address - Address in blockchain.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
getUnconfirmedByAddress(address, queryParams = {}) {
const combinedQueryParams = {
index: 0, // First index of returned results.
limit: 50, // Sets the number of returned results.
...queryParams,
};

return this.request.get(this.basePath + this.getSelectedNetwork() + '/address/' + address + '/unconfirmed-transactions', combinedQueryParams);
}

/**
* Multiple Addresses Info Endpoint
*
Expand Down
25 changes: 25 additions & 0 deletions src/common/blockchain/base-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,31 @@ class BaseTransaction extends BaseChainComponent {
return this.request.post(this.basePath + this.getSelectedNetwork() + '/txs/refund', data, queryParams);
}

/**
* Transaction Size for HD Wallet
*
* @async
* @desc Using this endpoint you can get the approximate size of a transaction in HD wallet.
*
* @param {string} walletName
* @param {string} password
* @param {array} outputs
* @param {object} [optData] - Optional data.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise|Promise<any>}
*/
getTransactionSizeForHDWallet(walletName, password, outputs, optData = {}, queryParams = {}) {
const data = {
...optData,
walletName,
password,
outputs,
};

return this.request.post(this.basePath + this.getSelectedNetwork() + '/wallets/hd/txs/size ', data, queryParams);
}

}

module.exports = BaseTransaction;
2 changes: 1 addition & 1 deletion src/rest-apis/blockchain/ETH/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const Blockchain = require('../../../common/blockchain/base-blockchain');
const Contract = require('../../../common/blockchain/eth-base-contract');
const Address = require('../../../common/blockchain/eth-base-address');
const PaymentForwarding = require('../../../common/blockchain/eth-base-payment-forwarding');
const Transaction = require('../../../common/blockchain/eth-base-transaction');

const Token = require('./token');
const Transaction = require('./transaction');
const Webhook = require('./webhook');

const ID = 'eth';
Expand Down
4 changes: 2 additions & 2 deletions src/rest-apis/blockchain/ETH/transaction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const EthBaseTransaction = require('../../../common/blockchain/eth-base-transaction');

class ETHransaction extends EthBaseTransaction {
class ETHTransaction extends EthBaseTransaction {

/**
* Get Internal Transactions Endpoint
Expand All @@ -19,4 +19,4 @@ class ETHransaction extends EthBaseTransaction {

}

module.exports = ETHransaction;
module.exports = ETHTransaction;
58 changes: 58 additions & 0 deletions src/rest-apis/blockchain/ZIL/address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const BaseChainComponent = require('../../../common/blockchain/base-chain-component');

class ZILAddress extends BaseChainComponent {

/**
* Address Endpoint
*
* @async
* @desc The default Address Endpoint strikes a general information about addresses.
*
* @param {string} address - Address in blockchain.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
getInfo(address, queryParams = {}) {
return this.request.get(this.basePath + this.getSelectedNetwork() + '/address/' + address, queryParams);
}

/**
* Generate Address Endpoint
*
* @async
* @desc The Generate Address endpoint allows you to generate private-public key-pairs along with an associated public address.
*
* @param {object} [optData] - Optional data.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
generateAddress(optData = {}, queryParams = {}) {
return this.request.post(this.basePath + this.getSelectedNetwork() + '/address', optData, queryParams);
}

/**
* Address Transactions Endpoint
*
* @async
* @desc The Address Transactions Endpoint returns all information available about a particular address, including an array of complete transactions.
*
* @param {string} address - Address in blockchain.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
getAddressTransactions(address, queryParams = {}) {
const combinedQueryParams = {
index: 0, // First index of returned results.
limit: 50, // Sets the number of returned results.
...queryParams,
};

return this.request.get(this.basePath + this.getSelectedNetwork() + '/address/' + address + '/transactions', combinedQueryParams);
}

}

module.exports = ZILAddress;
28 changes: 28 additions & 0 deletions src/rest-apis/blockchain/ZIL/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const BlockchainNetwork = require('../../../common/blockchain/blockchain-network');

const Blockchain = require('../../../common/blockchain/base-blockchain');

const Address = require('./address');
const Transaction = require('./transaction');

const ID = 'zil';
const NETWORKS = {
MAINNET: 'mainnet',
};

class ZIL extends BlockchainNetwork {

constructor(...props) {
super(...props, ID, NETWORKS, NETWORKS.MAINNET);

this.address = new Address(...props, ID);
this.blockchain = new Blockchain(...props, ID);
this.transaction = new Transaction(...props, ID);
}

}

module.exports = {
ZIL,
NETWORKS,
};
78 changes: 78 additions & 0 deletions src/rest-apis/blockchain/ZIL/transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const BaseChainComponent = require('../../../common/blockchain/base-chain-component');

class ZILTransaction extends BaseChainComponent {

/**
* Transaction Hash Endpoint
*
* @async
* @desc The Transaction Hash Endpoint returns detailed information about a given transaction based on its hash.
*
* @param {string} txHash - Hash of the transaction in blockchain.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
getTransaction(txHash, queryParams = {}) {
return this.request.get(this.basePath + this.getSelectedNetwork() + '/txs/hash/' + txHash, queryParams);
}

/**
* Transactions Index Endpoint by Index, Limit and Block Number
*
* @async
* @desc The Transaction Index Endpoint by Index, Limit and Block Number returns detailed information about
* transactions for the block height defined, starting from the index defined up to the limit defined.
*
* @param {number} block - Block number.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
getTransactionsByBlock(block, queryParams = {}) {
const combinedQueryParams = {
index: 0, // Index - start from.
limit: 50, // Limit - up to.
...queryParams,
};

return this.request.get(this.basePath + this.getSelectedNetwork() + '/txs/block/' + block, combinedQueryParams);
}

/**
* Transactions Index Endpoint by Block Number
*
* @async
* @desc The Transaction Index Endpoint by Block Number returns detailed information about a given transaction based
* on its index and block height.
*
* @param {number} blockNumber - Block height.
* @param {number} txIndex - Index of the transaction in block.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
getTransactionByBlockNumber(blockNumber, txIndex, queryParams = {}) {
return this.request.get(this.basePath + this.getSelectedNetwork() + '/txs/block/' + blockNumber + '/' + txIndex, queryParams);
}

/**
* Transactions Index Endpoint by Block Hash
*
* @async
* @desc The Transaction Index Endpoint by Block Hash returns detailed information about a given transaction based
* on its index and block hash.
*
* @param {string} blockHash - Block hash.
* @param {number} txIndex - Index of the transaction in block.
* @param {object} [queryParams] - Additional query parameters.
*
* @returns {*|Promise<any | never>}
*/
getTransactionByBlockHash(blockHash, txIndex, queryParams = {}) {
return this.request.get(this.basePath + this.getSelectedNetwork() + '/txs/block/' + blockHash + '/' + txIndex, queryParams);
}

}

module.exports = ZILTransaction;
2 changes: 2 additions & 0 deletions src/rest-apis/blockchain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {DOGE} = require('./DOGE');
const {ETC} = require('./ETC');
const {ETH} = require('./ETH');
const {LTC} = require('./LTC');
const {ZIL} = require('./ZIL');

class Blockchain {

Expand All @@ -16,6 +17,7 @@ class Blockchain {
this.ETC = new ETC(...props);
this.ETH = new ETH(...props);
this.LTC = new LTC(...props);
this.ZIL = new ZIL(...props);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const DOGE = require('./rest-apis/blockchains/DOGE');
const ETC = require('./rest-apis/blockchains/ETC');
const ETH = require('./rest-apis/blockchains/ETH');
const LTC = require('./rest-apis/blockchains/LTC');
const ZIL = require('./rest-apis/blockchains/ZIL');

(async function () {
if (!process.argv[2]) {
Expand All @@ -32,4 +33,5 @@ const LTC = require('./rest-apis/blockchains/LTC');
await ETC(caClient);
await ETH(caClient);
await LTC(caClient);
await ZIL(caClient);
})();
9 changes: 9 additions & 0 deletions tests/rest-apis/blockchains/ZIL/address.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
async function Address(caClient) {
console.log('\n::ZIL Address');

const newAddress = await caClient.BC.ZIL.address.generateAddress().then(response => response.payload.bechAddress);
await caClient.BC.ZIL.address.getInfo(newAddress);
await caClient.BC.ZIL.address.getAddressTransactions(newAddress);
}

module.exports = Address;
Loading

0 comments on commit c660ab8

Please sign in to comment.