From 0c0baec2945e6bfa29412c0318794c4daedf3b70 Mon Sep 17 00:00:00 2001 From: allemanfredi Date: Thu, 20 Feb 2020 18:58:53 +0100 Subject: [PATCH] chore(docs): <- updates this --- resources/docs/ptokens-node-selector.md | 47 ++++++----- resources/docs/ptokens-node.md | 82 +++++++++--------- resources/docs/ptokens-pbtc.md | 105 +++++++++++++++++------ resources/docs/ptokens-pltc.md | 106 +++++++++++++++++------- resources/docs/ptokens-utils.md | 22 +++-- resources/docs/ptokens.md | 61 +++++++++----- 6 files changed, 279 insertions(+), 144 deletions(-) diff --git a/resources/docs/ptokens-node-selector.md b/resources/docs/ptokens-node-selector.md index 98d1b8d2..ccfa37e4 100644 --- a/resources/docs/ptokens-node-selector.md +++ b/resources/docs/ptokens-node-selector.md @@ -2,18 +2,18 @@ This is the module that allows to instantiate a class for selecting a validator Node -### Installation +  -It is possible to install individually this package without installing the main one (__`ptokens`__). +### Installation ``` npm install ptokens-node-selector ``` -### Usage -If no default node is used, the first available will be selected (randomly). -If an unavailable node is selected during the initialization (__`new NodeSelector({...})`__), another one will be searched. -It is also possible to set a node manually using the __`set`__ function +  + +## Usage +In the situation where no default node is in use, the library randomly selects a node among the ones available. Similarly, if the default node (__`defaultEndoint`__) happens to be unavailable during the initialisation process (__`new NodeSelector({...})`__), the library will search for another one. Manual setting of nodes is possible via the __`set`__ function ```js import { NodeSelector } from 'ptokens-node-selector' @@ -27,8 +27,12 @@ const node = new Node({ }) ``` +  + *** +  + ## Class Methods * __`checkConnection`__ @@ -42,23 +46,23 @@ const node = new Node({ ## checkConnection ```js -ptokens.nodeSelector.checkConnection(endpoint, timeout) +nodeSelector.checkConnection(endpoint, timeout) ``` -Check if a node is available +Function to check whether a node is available or not. ### Parameters - __`String`__ - __`endpoint`__: node endpoint -- __`String`__ - __`timeout`__: timeout (in ms) after which the connection fails +- __`String`__ - __`timeout`__: time span (in milliseconds) after which the connection fails ### Returns -- __`Promise`__ : when resolved, a boolean indicating if the node is available +- __`Promise`__ : when resolved, a boolean indicating if the node is available. ### Example ```js -ptokens.nodeSelector.checkConnection('https://....', 1000).then(status => console.log(status)) +nodeSelector.checkConnection('https://....', 1000).then(status => console.log(status)) ```   @@ -66,10 +70,10 @@ ptokens.nodeSelector.checkConnection('https://....', 1000).then(status => consol ## getApi ```js -ptokens.nodeSelector.getApi() +nodeSelector.getApi() ``` -Return an instance of __`AxiosInstance`__ used to perform http requests. If no node is selected, it searches for one +Returns an instance of __`AxiosInstance`__ used to perform http requests. If no node is selected, it searches for one. ### Returns @@ -77,7 +81,7 @@ Return an instance of __`AxiosInstance`__ used to perform http requests. If no n ### Example ```js -ptokens.nodeSelector.getApi().then(api => api.get('http://...')) +nodeSelector.getApi().then(api => api.get('http://...')) ```   @@ -86,19 +90,18 @@ ptokens.nodeSelector.getApi().then(api => api.get('http://...')) ## select ```js -ptokens.nodeSelector.select() +nodeSelector.select() ``` -Selects a node. If no default node is used (during the initialization), the first available will be selected (randomly). -If an unavailable node is selected during the initialization (__`new NodeSelector({...})`__), another one will be searched. +If no default node is used, the first available will be selected (randomly). Similarly, if the default node (__`defaultEndoint`__) is unavailable, it will search for another one. ### Returns -- __`Promise`__ : an instance of Node +- __`Promise`__ : an instance of __`Node`__ ### Example ```js -ptokens.nodeSelector.select().then(selectedNode => { +nodeSelector.select().then(selectedNode => { console.log(selectedNode.endpoint) selectedNode.api.get('https://...') }) @@ -110,10 +113,10 @@ ptokens.nodeSelector.select().then(selectedNode => { ## set ```js -ptokens.nodeSelector.set(endpoint) +nodeSelector.set(endpoint) ``` -Set the selected node manually +A function that manually sets a specific node. ### Parameters @@ -125,7 +128,7 @@ Set the selected node manually ### Example ```js -const selectedNode = ptokens.nodeSelector.set('https://..') +const selectedNode = nodeSelector.set('https://..') console.log(selectedNode.endpoint) selectedNode.api.get('https://...') ``` diff --git a/resources/docs/ptokens-node.md b/resources/docs/ptokens-node.md index c5f9beb0..dfd7e95c 100644 --- a/resources/docs/ptokens-node.md +++ b/resources/docs/ptokens-node.md @@ -1,15 +1,17 @@ # ptokens-node -This is the module that allows to interact with a Validator Node. +This module enables the interaction with a Node Validator. -### Installation +  -It is possible to install individually this package without installing the main one (__`ptokens`__). +### Installation ``` npm install ptokens-node ``` +  + ### Usage ```js @@ -24,8 +26,12 @@ const node = new Node({ }) ``` +  + *** +  + ## Class Methods * __`getBroadcastTransactionStatus`__ @@ -45,10 +51,10 @@ const node = new Node({ ## getBroadcastTransactionStatus ```js -ptokens.node.getBroadcastTransactionStatus(hash) +node.getBroadcastTransactionStatus(hash) ``` -Gets the status of a broadcasted transaction by the Node. +Gets the status of a transaction broadcasted by the Node. ### Parameters @@ -56,11 +62,11 @@ Gets the status of a broadcasted transaction by the Node. ### Returns -- __`Promise`__ : when resolved, returns the information about a broadcasted transaction by the Node +- __`Promise`__ : when resolved, it returns the details of the transaction broadcasted by the Node ### Example ```js -ptokens.node.getBroadcastTransactionStatus('0x80b97c8d9676915a0c51c66468eeb1745a6fdd70063f2fb0412fd1e01b7cd083').then(status => console.log(status)) +node.getBroadcastTransactionStatus('0x80b97c8d9676915a0c51c66468eeb1745a6fdd70063f2fb0412fd1e01b7cd083').then(report => console.log(report)) ```   @@ -68,7 +74,7 @@ ptokens.node.getBroadcastTransactionStatus('0x80b97c8d9676915a0c51c66468eeb1745a ## getIncomingTransactionStatus ```js -ptokens.node.getIncomingTransactionStatus(hash) +node.getIncomingTransactionStatus(hash) ``` Gets the status of an incoming transaction to the Node. @@ -79,11 +85,11 @@ Gets the status of an incoming transaction to the Node. ### Returns -- __`Promise`__ : when resolved returns the information about an incoming transaction to the Node +- __`Promise`__ : when resolved, it returns the details of the incoming transaction to the Node ### Example ```js -ptokens.node.getIncomingTransactionStatus('c1e09684a51f756230f16aba30739a8e0744e2125ab3893669483ae65ea3ecd3').then(status => console.log(status)) +node.getIncomingTransactionStatus('c1e09684a51f756230f16aba30739a8e0744e2125ab3893669483ae65ea3ecd3').then(status => console.log(status)) ```   @@ -92,10 +98,10 @@ ptokens.node.getIncomingTransactionStatus('c1e09684a51f756230f16aba30739a8e0744e ## getInfo ```js -ptokens.node.getInfo(nativeNetwork, hostNetwork) +node.getInfo(nativeNetwork, hostNetwork) ``` -return info about smart contract address and enclave public key +The function returns the details of the smart contract addess and the enclave public key. ### Parameters @@ -104,11 +110,11 @@ return info about smart contract address and enclave public key ### Returns -- __`Promise`__ : when resolved returns the node infos +- __`Promise`__ : when resolved, it returns the node details ### Example ```js -ptokens.node.getInfo('testnet', 'ropsten').then(status => console.log(status)) +node.getInfo('testnet', 'ropsten').then(info => console.log(info)) ```   @@ -118,10 +124,10 @@ ptokens.node.getInfo('testnet', 'ropsten').then(status => console.log(status)) ## getLastProcessedBlock ```js -ptokens.node.getLastProcessedBlock(type) +node.getLastProcessedBlock(type) ``` -Gets the last processed block by the Node of a given type. +Gets the last block of a given type processed by the Node. ### Parameters @@ -129,11 +135,11 @@ Gets the last processed block by the Node of a given type. ### Returns -- __`Promise`__ : when resolved returns the last processed block by the Node given its type +- __`Promise`__ : when resolved, it returns the last block of a given type processed by the Node ### Example ```js -ptokens.node.getLastProcessedBlock('host').then(block => console.log(block)) +node.getLastProcessedBlock('host').then(block => console.log(block)) ```   @@ -142,14 +148,14 @@ ptokens.node.getLastProcessedBlock('host').then(block => console.log(block)) ## getReports ```js -ptokens.node.getReports(type, limit) +node.getReports(type, limit) ``` -Gets a report of the transactions relating to the `type` signature nonce supplied. A report is a list of the last `limit` minting/burning transactions. For example in case of `pBTC`, a report of `host` type consists of a list of all burning transactions. +Gets a report of the transactions relating to the `type` signature nonce supplied. A report is a list of the last `limit` minting/burning transactions. For example, in the case of __`pBTC`__, a report of __`host`__ type is represented by a list of all transactions involving a token burn. ### Parameters -- __`String`__ - __`type`__: type of report to get: Values can be: `host` and `native` +- __`String`__ - __`type`__: type of report to get. Values can be: `host` and `native` - __`Number`__ - __`limit`__: maximum number of reports to be received. The default value is set to `100` ### Returns @@ -158,7 +164,7 @@ Gets a report of the transactions relating to the `type` signature nonce supplie ### Example ```js -ptokens.node.getReports('native', 1).then(report => console.log(report)) +node.getReports('native', 1).then(report => console.log(report)) ```   @@ -169,14 +175,14 @@ ptokens.node.getReports('native', 1).then(report => console.log(report)) ## getReportsByAddress ```js -ptokens.node.getReportsByAddress(type, address, limit) +node.getReportsByAddress(type, address, limit) ``` -Returns all reports given an address +Given an address, it returns all reports related to such an address. ### Parameters -- __`String`__ - __`type`__: type of report to get: Values can be: `host` and `native` +- __`String`__ - __`type`__: type of report to get. Values can be: `host` and `native` - __`String`__ - __`address`__: `host` or `native` address - __`Number`__ - __`limit`__: maximum number of reports to be received. The default value is set to `100` @@ -186,7 +192,7 @@ Returns all reports given an address ### Example ```js -ptokens.node.getReportsByAddress('native', '0x1f0b6A3AC984B4c990d8Ce867103E9C384629747', 1).then(report => console.log(report)) +node.getReportsByAddress('native', '0x1f0b6A3AC984B4c990d8Ce867103E9C384629747', 1).then(report => console.log(report)) ```   @@ -197,10 +203,10 @@ ptokens.node.getReportsByAddress('native', '0x1f0b6A3AC984B4c990d8Ce867103E9C384 ## getReportsByNonce ```js -ptokens.node.getReportsByNonce(type, nonce, limit) +node.getReportsByNonce(type, nonce, limit) ``` -Returns all reports given a nonce +Given a nonce, it returns all reports related to such a nonce. ### Parameters @@ -214,7 +220,7 @@ Returns all reports given a nonce ### Example ```js -ptokens.node.getReportsByNonce('native', 1, 1).then(report => console.log(report)) +node.getReportsByNonce('native', 1, 1).then(report => console.log(report)) ```   @@ -224,18 +230,18 @@ ptokens.node.getReportsByNonce('native', 1, 1).then(report => console.log(report ## ping ```js -ptokens.node.ping() +node.ping() ``` -Check that the Node is running. +Checks that the Node is running. ### Returns -- __`Promise`__ : when resolved return a string +- __`Promise`__ : when resolved, it returns a string ### Example ```js -ptokens.node.ping().then(res => console.log(res)) +node.ping().then(res => console.log(res)) ```   @@ -244,19 +250,19 @@ ptokens.node.ping().then(res => console.log(res)) ## submitBlock ```js -ptokens.node.submitBlock(type, block) +node.submitBlock(type, block) ``` -Submit a valid block to the Node specifying its type. +Submits a valid block to the Node specifying its type. ### Parameters - __`Object`__ - __`type`__: type of the submitted block. Values can be: `native` and `host` -- __`Object`__ - __`block`__: valid block +- __`Object`__ - __`block`__: valid block in JSON format ### Returns -- __`Promise`__ : when resolved returs a string that specify if the submission succedeed +- __`Promise`__ : when resolved, it returns a string that specifies whether the submission of the block was successful ### Example ```js @@ -282,7 +288,7 @@ const block = { ], "uncles": [] } -ptokens.node.submitBlock('host', block).then(res => console.log(res)) +node.submitBlock('host', block).then(res => console.log(res)) ```   \ No newline at end of file diff --git a/resources/docs/ptokens-pbtc.md b/resources/docs/ptokens-pbtc.md index 739efb7c..ce13e20c 100644 --- a/resources/docs/ptokens-pbtc.md +++ b/resources/docs/ptokens-pbtc.md @@ -1,17 +1,56 @@ # ptokens-pbtc -This module allows to interact with pBTC token. +This module enables the interaction with pBTC tokens. -### Installation +  -It is possible to install individually this package without installing the main one (__`ptokens`__). +### Installation ``` npm install ptokens-pbtc ``` +  + +*** + +  + +## Usage + + +### Peg-in + + +```js +import { pBTC } from 'ptokens-pbtc' + +const pbtc = new pBTC({ + ethPrivateKey: 'Eth private key', + ethProvider: 'Eth provider', + btcNetwork: 'testnet' //'testnet' or 'bitcoin', default 'testnet' +}) + +const depositAddress = await pbtc.getDepositAddress() + +console.log(depositAddress.toString()) + +//fund the BTC address just generated (not ptokens.js stuff) + +depositAddress.waitForDeposit() + .once('onBtcTxBroadcasted', tx => ... ) + .once('onBtcTxConfirmed', tx => ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeReceivedTx', report => ...) + .once('onEthTxConfirmed', tx => ...) + .then(res => ...)) + +``` + +  + +### Peg-out -### Usage ```js import { pBTC } from 'ptokens-pbtc' @@ -21,7 +60,17 @@ const pbtc = new pBTC({ ethProvider: 'Eth provider', btcNetwork: 'testnet' //'testnet' or 'bitcoin', default 'testnet' }) + +pbtc.redeem(amount, btcAddress) + .once('onEthTxConfirmed', tx => ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeBroadcastedTx', report => ...) + .once('onBtcTxConfirmed', tx => ...) + .then(res => ...) ``` + +  + It is possible to pass a standard Ethereum Provider as the __`ethProvider`__ value, such as the one injected into the content script of each web page by Metamask(__`window.web3.currentProvider`__). @@ -38,9 +87,12 @@ if (window.web3) { console.log('No web3 detected') } ``` +  *** +  + ## Class Methods * __`approve`__ @@ -69,7 +121,7 @@ ptokens.pbtc.approve(spender, amount) - __`String`__ - __`spender`__: spender Ethereum address - __`Number`__ - __`amount`__: amount to transfer -Approve to spend the specified amount of pBTC to the provided Ethereum address by setting the allowance of spender address +Approves to send the specified amount of pBTC to the provided Ethereum address by setting the allowance of spender address ### Returns @@ -88,7 +140,7 @@ ptokens.pbtc.approve('eth address', 1.3452).then(status => console.log(status)) ptokens.pbtc.getAllowance(owner, spender) ``` -Get the remaining number of pBTC that `spender` can spend spend on behalf of `owner` through `transferFrom` +Get the remaining number of pBTC that `spender` can spend on behalf of `owner` through `transferFrom` ### Parameters @@ -97,7 +149,7 @@ Get the remaining number of pBTC that `spender` can spend spend on behalf of `ow ### Returns -- __`Number`__ : number of pBTC that `spender` can spend spend on behalf of `owner` through `transferFrom` +- __`Number`__ : number of pBTC that `spender` can spend on behalf of `owner` through `transferFrom` ### Example ```js @@ -141,7 +193,7 @@ Get the total number of Burn events ### Returns -- __`Number`__ : current number of burning events +- __`Number`__ : current number of burn events ### Example ```js @@ -271,25 +323,25 @@ ptokens.pbtc.getTotalRedeemed().then(totalRedeemed => console.log(totalRedeemed) ptokens.pbtc.redeem(amount, btcAddress) ``` -Redeem a specified number of pBTC to the specified BTC account. +Redeem a specified number of pBTC to the specified BTC address. ### Parameters - __`Number`__ - __`amount`__: amount of pBTC to redeem -- __`String`__ - __`btcAddress`__: BTC account on which receive back the deposited BTC +- __`String`__ - __`btcAddress`__: BTC address where to receive the BTC redeemed ### Returns -- __`Promievent`__ : A [promise combined event emitter](https://web3js.readthedocs.io/en/v1.2.0/callbacks-promises-events.html#promievent). Will be resolved when the Node redeemd the specified amount of pBTC +- __`Promievent`__ : A [promise combined event emitter](https://web3js.readthedocs.io/en/v1.2.0/callbacks-promises-events.html#promievent). Will be resolved when the Node redeemd the specified amount of pBTC redeemed. ### Example ```js ptokens.pbtc.redeem(1, 'btc address') - .once('onEthTxConfirmed', e => { console.log(e) }) - .once('onNodeReceivedTx', e => { console.log(e) }) - .once('onNodeBroadcastedTx', e => { console.log(e) }) - .once('onLtcTxConfirmed', e => { console.log(e) }) - .then(res => { console.log(res) }) + .once('onEthTxConfirmed', tx =>. ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeBroadcastedTx', report => ...) + .once('onBtcTxConfirmed', tx => ...) + .then(res => ...) ```   @@ -310,7 +362,7 @@ Transfer a specified amount of pBTC to the provided Ethereum address ### Returns -- __`Boolean`__ : boolean value indicating whether transfer operation succeeded +- __`Boolean`__ : boolean value indicating whether the transfer operation succeeded ### Example ```js @@ -359,7 +411,7 @@ import { BtcDepositAddress } from 'ptokens-pbtc' const depositAddress = new BtcDepositAddress({ web3: new Web3(...) - node: new NodeSelector({...}) + node: new Node({...}) network: 'testnet' //'testnet' or 'bitcoin', default 'testnet' }) ``` @@ -403,7 +455,7 @@ depositAddress.generate('eth address').then(addr => console.log(addr)) depositAddress.toString() ``` -Generate a BTC address as string +Returns a BTC address in the form of a string. ### Returns @@ -421,8 +473,7 @@ console.log(depositAddress.toString()) depositAddress.verify() ``` -Check that the deposit address matches with the expected address - +Checks that the deposit address matches with the expected address. ### Returns @@ -450,10 +501,10 @@ Monitors the pBTC minting process ### Example ```js depositAddress.waitForDeposit( - .once('onBtcTxBroadcasted', e => { console.log(e) }) - .once('onBtcTxConfirmed', e => { console.log(e) }) - .once('onNodeReceivedTx', e => { console.log(e) }) - .once('onNodeBroadcastedTx', e => { console.log(e) }) - .once('onEthTxConfirmed', e => { console.log(e) }) - .then(res => { console.log(res) }) + .once('onBtcTxBroadcasted', tx => ...) + .once('onBtcTxConfirmed', tx => ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeBroadcastedTx', report => ...) + .once('onEthTxConfirmed', tx => ...) + .then(res => res => ...) ``` \ No newline at end of file diff --git a/resources/docs/ptokens-pltc.md b/resources/docs/ptokens-pltc.md index c1bdb9ef..fc262865 100644 --- a/resources/docs/ptokens-pltc.md +++ b/resources/docs/ptokens-pltc.md @@ -1,17 +1,25 @@ -# ptokens-ltc +# ptokens-pltc -This module allows to interact with pLTC token. +This module enables the interaction with pLTC tokens. -### Installation +  -It is possible to install individually this package without installing the main one (__`ptokens`__). +### Installation ``` npm install ptokens-pltc ``` +  + +*** + +  + +## Usage + +### Peg-in -### Usage ```js import { pLTC } from 'ptokens-pltc' @@ -21,7 +29,47 @@ const pltc = new pLTC({ ethProvider: 'Eth provider', ltcNetwork: 'testnet' //'testnet' or 'litecoin', default 'testnet' }) + +const depositAddress = await pltc.getDepositAddress() + +console.log(depositAddress.toString()) + +//fund the LTC address just generated (not ptokens.js stuff) + +depositAddress.waitForDeposit() + .once('onLtcTxBroadcasted', tx => ... ) + .once('onLtcTxConfirmed', tx => ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeReceivedTx', report => ...) + .once('onEthTxConfirmed', tx => ...) + .then(res => ...)) + ``` + +  + +### Peg-out + + +```js +import { pLTC } from 'ptokens-pltc' + +const pltc = new pLTC({ + ethPrivateKey: 'Eth private key', + ethProvider: 'Eth provider', + ltcNetwork: 'testnet' //'testnet' or 'litecoin', default 'testnet' +}) + +pltc.redeem(amount, btcAddress) + .once('onEthTxConfirmed', tx => ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeBroadcastedTx', report => ...) + .once('onLtcTxConfirmed', tx => ...) + .then(res => ...) +``` + +  + It is possible to pass a standard Ethereum Provider as the __`ethProvider`__ value, such as the one injected into the content script of each web page by Metamask(__`window.web3.currentProvider`__). @@ -38,9 +86,12 @@ if (window.web3) { console.log('No web3 detected') } ``` +  *** +  + ## Class Methods * __`approve`__ @@ -69,7 +120,7 @@ ptokens.pltc.approve(spender, amount) - __`String`__ - __`spender`__: spender Ethereum address - __`Number`__ - __`amount`__: amount to transfer -Approve to spend the specified amount of pLTC to the provided Ethereum address by setting the allowance of spender address +Approves to send the specified amount of pLTC to the provided Ethereum address by setting the allowance of spender address ### Returns @@ -93,11 +144,11 @@ ptokens.pltc.getAllowance(owner, spender) - __`String`__ - __`owner`__: Owner Ethereum address - __`String`__ - __`spender`__: Spender Ethereum address -Get the remaining number of pLTC that `spender` can spend spend on behalf of `owner` through `transferFrom` +Get the remaining number of pLTC that `spender` can spend on behalf of `owner` through `transferFrom` ### Returns -- __`Number`__ : number of pLTC that `spender` can spend spend on behalf of `owner` through `transferFrom` +- __`Number`__ : number of pLTC that `spender` can spend on behalf of `owner` through `transferFrom` ### Example ```js @@ -139,7 +190,7 @@ ptokens.pltc.getBurnNonce() ### Parameters -Get the total number of Burn events +Gets the total number of Burn events ### Returns @@ -281,25 +332,25 @@ ptokens.pltc.getTotalRedeemed().then(totalRedeemed => console.log(totalRedeemed) ptokens.pltc.redeem(amount, ltcAddress) ``` -Redeem a specified number of pLTC to the specified LTC account. +Redeem a specified number of pLTC to the specified LTC address. ### Parameters - __`Number`__ - __`amount`__: amount of pLTC to redeem -- __`String`__ - __`ltcAddress`__: LTC address on which receive back the deposited LTC +- __`String`__ - __`ltcAddress`__: LTC address where to receive the LTC redeemed ### Returns -- __`Promievent`__ : A [promise combined event emitter](https://web3js.readthedocs.io/en/v1.2.0/callbacks-promises-events.html#promievent). Will be resolved when the Enclave redeemd the specified amount of pLTC +- __`Promievent`__ : A [promise combined event emitter](https://web3js.readthedocs.io/en/v1.2.0/callbacks-promises-events.html#promievent). Will be resolved when the Enclave redeemd the specified amount of pLTC redeemed ### Example ```js ptokens.pltc.redeem(1, 'litecoin address') - .once('onEthTxConfirmed', e => { console.log(e) }) - .once('onNodeReceivedTx', e => { console.log(e) }) - .once('onNodeBroadcastedTx', e => { console.log(e) }) - .once('onLtcTxConfirmed', e => { console.log(e) }) - .then(res => { console.log(res) }) + .once('onEthTxConfirmed', tx =>. ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeBroadcastedTx', report => ...) + .once('onLtcTxConfirmed', tx => ...) + .then(res => ...) ```   @@ -319,7 +370,7 @@ Transfer a specified amount of pLTC to the provided Ethereum address ### Returns -- __`Boolean`__ : boolean value indicating whether transfer operation succeeded +- __`Boolean`__ : boolean value indicating whether the transfer operation succeeded ### Example ```js @@ -361,7 +412,7 @@ import { LtcDepositAddress } from 'ptokens-pltc' const depositAddress = new LtcDepositAddress({ web3: new Web3(...) node: new NodeSelector({...}) - network: 'testnet' //'testnet' or 'bitcoin', default 'testnet' + network: 'testnet' //'testnet' or 'litecoin', default 'testnet' }) ``` @@ -404,7 +455,7 @@ depositAddress.generate('eth address').then(addr => console.log(addr)) depositAddress.toString() ``` -Generate a LTC address as string +Returns a LTC address in the form of a string ### Returns @@ -422,8 +473,7 @@ console.log(depositAddress.toString()) depositAddress.verify() ``` -Check that the deposit address matches with the expected address - +Checks that the deposit address matches with the expected address. ### Returns @@ -451,10 +501,10 @@ Monitors the pLTC minting process ### Example ```js depositAddress.waitForDeposit( - .once('onLtcTxBroadcasted', e => { console.log(e) }) - .once('onLtcTxConfirmed', e => { console.log(e) }) - .once('onNodeReceivedTx', e => { console.log(e) }) - .once('onNodeBroadcastedTx', e => { console.log(e) }) - .once('onEthTxConfirmed', e => { console.log(e) }) - .then(res => { console.log(res) }) + .once('onLtcTxBroadcasted', tx => ...) + .once('onLtcTxConfirmed', tx => ...) + .once('onNodeReceivedTx', report => ...) + .once('onNodeBroadcastedTx', report => ...) + .once('onEthTxConfirmed', tx => ...) + .then(res => ...) ``` \ No newline at end of file diff --git a/resources/docs/ptokens-utils.md b/resources/docs/ptokens-utils.md index 3533e037..a8f040c4 100644 --- a/resources/docs/ptokens-utils.md +++ b/resources/docs/ptokens-utils.md @@ -1,17 +1,21 @@ # ptokens-utils -This module allows to have access to some useful utilities used by other packages. +This module enables access to some useful utilities used by other packages. -### Installation +  -It is possible to install individually this package without installing the main one (__`ptokens`__). +### Installation ``` npm install ptokens-utils ``` +  + *** +  + ## utils.btc ## btc.broadcastTransaction @@ -20,7 +24,7 @@ npm install ptokens-utils ptokens.utils.btc.broadcastTransaction(network, transaction) ``` -Broadcast a Bitcoin transaction using Blockstream Esplora API +Broadcasts a Bitcoin transaction using Blockstream Esplora API ### Parameters @@ -44,7 +48,7 @@ const isBroadcasted = await utils.btc.broadcastTransaction('testnet', 'tx hex') ptokens.utils.btc.getUtxoByAddress(network, address) ``` -Return all UTXOs belonging to a Bitcoin address +Returns all UTXOs belonging to a Bitcoin address ### Parameters @@ -68,7 +72,7 @@ const utxos = await utils.btc.getUtxoByAddress('testnet', 'mk8aUY9DgFMx7VfDck5oQ ptokens.utils.btc.getTransactionHexById(network, transactionId) ``` -Return a transaction in hex format +Returns a transaction in hex format ### Parameters @@ -115,7 +119,7 @@ utils.btc.isValidAddress('mk8aUY9DgFMx7VfDck5oQ7FjJNhn8u3snP') //true ptokens.utils.btc.monitorUtxoByAddress(network, address, eventEmitter, pollingTime) ``` -Allow to monitor if an address is receving a transaction +Allows to monitor if an address is receving a transaction ### Parameters @@ -564,7 +568,7 @@ const isBroadcasted = await utils.ltc.broadcastTransaction('testnet', 'tx hex') ptokens.utils.ltc.getUtxoByAddress(network, address) ``` -Return all UTXOs belonging to a Litecoin address +Returns all UTXOs belonging to a Litecoin address ### Parameters @@ -588,7 +592,7 @@ const utxos = await utils.ltc.getUtxoByAddress('testnet', 'mk8aUY9DgFMx7VfDck5oQ ptokens.utils.ltc.getTransactionHexById(network, transactionId) ``` -Return a transaction in hex format +Returns a transaction in hex format ### Parameters diff --git a/resources/docs/ptokens.md b/resources/docs/ptokens.md index 11b7fce8..b545abcb 100644 --- a/resources/docs/ptokens.md +++ b/resources/docs/ptokens.md @@ -3,30 +3,25 @@ This is the main module that allows you to instantiate an instance of all available pTokens. -### Structure -- __`Object`__ - __`pbtc`__: class for interacting with pBTC token -- __`Object`__ - __`pltc`__: class for interacting with pLTC token -- __`Object`__ - __`utils`__: some usefull utilities -### Constructor parameters -- __`Object`__ - __`configs`__: options for initializing a pTokens instance - - __`Object`__ - __`pbtc`__: options for initializing pBTC - - __`String`__ - __`ethPrivateKey`__: an Ethereum private key used for signing transactions for redeeming pTokens (this can be null if you pass an already initialized instance of __`ethProvider`__) - - __`String`__ | __`Object`__ - __`ethProvider`__: an Ethereum provider - - __`String`__ - __`btcNetwork`__: Can be `bitcoin` or `testnet` - - __`String`__ - __`defaultNode`__: (Optional) - - __`Object`__ - __`pltc`__: options for initializing pBTC - - __`String`__ - __`ethPrivateKey`__: an Ethereum private key used for signing transactions for redeeming pTokens (this can be null if you pass an already initialized instance of __`ethProvider`__) - - __`String`__ | __`Object`__ - __`ethProvider`__: an Ethereum provider - - __`String`__ - __`ltcNetwork`__: Can be `litecoin` or `testnet` - - __`String`__ - __`defaultNode`__: (Optional) +  + +### Installation + +``` +npm install ptokens +``` + +  + +***   -### Usage: +### Usage ```js -const pTokens = require('ptokens') +import pTokens from 'ptokens' const ptokens = new pTokens({ pbtc: { @@ -41,11 +36,13 @@ const ptokens = new pTokens({ } }) ``` + + It is possible to pass a standard Ethereum Provider as the __`ethProvider`__ value, such as the one injected into the content script of each web page by Metamask(__`window.web3.currentProvider`__). ```js -const pTokens = require('ptokens') +import pTokens from 'ptokens' if (window.web3) { @@ -62,4 +59,28 @@ if (window.web3) { } else { console.log('No web3 detected') } -``` \ No newline at end of file +``` + +  + +### Structure +- __`Object`__ - __`pbtc`__: class for interacting with pBTC token +- __`Object`__ - __`pltc`__: class for interacting with pLTC token +- __`Object`__ - __`utils`__: some usefull utilities + +  + +### Constructor parameters +- __`Object`__ - __`configs`__: options for initializing a pTokens instance + - __`Object`__ - __`pbtc`__: options for initializing pBTC + - __`String`__ - __`ethPrivateKey`__: an Ethereum private key used for signing transactions for redeeming pTokens (this can be null if you pass an already initialized instance of __`ethProvider`__) + - __`String`__ | __`Object`__ - __`ethProvider`__: an Ethereum provider + - __`String`__ - __`btcNetwork`__: Can be `bitcoin` or `testnet` + - __`String`__ - __`defaultNode`__: (Optional) + - __`Object`__ - __`pltc`__: options for initializing pBTC + - __`String`__ - __`ethPrivateKey`__: an Ethereum private key used for signing transactions for redeeming pTokens (this can be null if you pass an already initialized instance of __`ethProvider`__) + - __`String`__ | __`Object`__ - __`ethProvider`__: an Ethereum provider + - __`String`__ - __`ltcNetwork`__: Can be `litecoin` or `testnet` + - __`String`__ - __`defaultNode`__: (Optional) + +