-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Crypto-APIs/CRYPTOAPIS-2387
#CRYPTOAPIS-2387
- Loading branch information
Showing
18 changed files
with
322 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.