Skip to content

Commit

Permalink
improve docs and custom address
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhson1085 committed May 27, 2020
1 parent 27d0ddb commit cf4841f
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 50 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -9,10 +9,10 @@ npm install --save bridgejs

```javascript
const BridgeJS = require('bridgejs')
const bridgejs = await BridgeJS.setProvider('https://bridge.tomochain.com')
const bridgejs = await BridgeJS.setProvider()

// get network information
let info = await BridgeJS.networkInformation('https://bridge.tomochain.com')
let info = await BridgeJS.networkInformation()
console.log(info)

// wait for new deposit
Expand All @@ -24,6 +24,8 @@ bridgejs.wrapWatch({ tokenSymbol }).then((ev) => {
})
```

Read more [BridgeJS Document](https://tomochain.github.io/bridgejs/BridgeJS.html)

Or you can use `bridge-cli` binary:
```
cd /tmp && wget https://github.com/tomochain/bridgejs/releases/download/[VERSION]/bridge-cli.[VERSION].linux-x64 -O bridge-cli
Expand Down
22 changes: 13 additions & 9 deletions bridge-cli
Expand Up @@ -77,7 +77,7 @@ function run() {
type : 'input',
name : 'endpoint',
message : 'Enter TomoBridge endpoint...',
default: 'https://bridge.devnet.tomochain.com'
default: 'https://bridge.tomochain.com'
}]
if (!params.keystore) {
questions.push({
Expand Down Expand Up @@ -196,12 +196,14 @@ function run() {
commander
.command('get-wrap-txs')
.description('get wrap transactions')
.requiredOption('-p --page <page>', 'page number')
.requiredOption('-l --limit <limit>', 'limit number')
.option('-p --page <page>', 'page number')
.option('-l --limit <limit>', 'limit number')
.option('-a --address <address>', 'user address')
.action(async (params) => {
await bridgejs.getWrapTransactions({
page: params.page,
limit: params.limit
page: params.page || 1,
limit: params.limit || 10,
userAddress: params.address
})
.then(data => {
console.log(data)
Expand All @@ -211,12 +213,14 @@ function run() {
commander
.command('get-unwrap-txs')
.description('get unwrap transactions')
.requiredOption('-p --page <page>', 'page number')
.requiredOption('-l --limit <limit>', 'limit number')
.option('-p --page <page>', 'page number')
.option('-l --limit <limit>', 'limit number')
.option('-a --address <address>', 'user address')
.action(async (params) => {
await bridgejs.getUnwrapTransactions({
page: params.page,
limit: params.limit
page: params.page || 1,
limit: params.limit || 10,
userAddress: params.address
})
.then(data => {
console.log(data)
Expand Down
27 changes: 15 additions & 12 deletions bridge.js
Expand Up @@ -59,8 +59,8 @@ class BridgeJS {

/**
* Initial the SDK
* @param {string} endpoint - The Url to the node
* @param {string} pkey - The private key of the coinbase
* @param {string} [endpoint=https://bridge.tomochain.com] - The Url to the node
* @param {string} [pkey=random] - The private key of the coinbase
*/
static setProvider(endpoint = 'https://bridge.tomochain.com', pkey = '') {
return BridgeJS.networkInformation(endpoint).then((config) => {
Expand Down Expand Up @@ -149,13 +149,14 @@ class BridgeJS {
* Get latest deposit transaction
* @param {Object} wrap The wrap information
* @param {string} wrap.tokenSymbol - The token symbol
* @param {string} wrap.userAddress - The user address
*
* @returns {Object} Transaction object(inner and outter networks)
*/
async getDepositTransaction ({ tokenSymbol }) {
async getDepositTransaction ({ tokenSymbol, userAddress = this.coinbase }) {
return new Promise((resolve, reject) => {
try {
let url = urljoin(this.endpoint, 'api/wrap/getTransaction/deposit/', tokenSymbol, this.coinbase)
let url = urljoin(this.endpoint, 'api/wrap/getTransaction/deposit/', tokenSymbol, userAddress)
let options = {
method: 'GET',
url: url,
Expand Down Expand Up @@ -183,16 +184,17 @@ class BridgeJS {
}

/**
* Get latest withdraw transction
* Get latest withdraw transaction
* @param {Object} unwrap The unwrap information
* @param {String} unwrap.tokenSymbol Token symbol
* @param {string} wrap.userAddress - The user address
*
* @returns {Object} Transaction object(inner and outter networks)
*/
async getWithdrawTransaction ({ tokenSymbol }) {
async getWithdrawTransaction ({ tokenSymbol, userAddress = this.coinbase }) {
return new Promise((resolve, reject) => {
try {
let url = urljoin(this.endpoint, 'api/wrap/getTransaction/withdraw/', tokenSymbol, this.coinbase)
let url = urljoin(this.endpoint, 'api/wrap/getTransaction/withdraw/', tokenSymbol, userAddress)
let options = {
method: 'GET',
url: url,
Expand Down Expand Up @@ -308,15 +310,16 @@ class BridgeJS {
* @param {Object} object Input object
* @param {Number} object.limit Limit number of records per page
* @param {Number} object.page Page number
* @param {string} wrap.userAddress - The user address
*
* @returns {Object} Transaction object(inner and outter networks)
*/
async getWrapTransactions ({ limit, page }) {
async getWrapTransactions ({ limit, page, userAddress = this.coinbase }) {
return new Promise((resolve, reject) => {
try {
let url = urljoin(
this.endpoint, 'api/transactions/getWrapTxs/',
`?address=${this.coinbase}`,
`?address=${userAddress}`,
`&page=${page}`,
`&limit=${limit}`
)
Expand Down Expand Up @@ -352,15 +355,16 @@ class BridgeJS {
* @param {Object} object Input object
* @param {Number} object.limit Limit number of records per page
* @param {Number} object.page Page number
* @param {string} wrap.userAddress - The user address
*
* @returns {Object} Transaction object(inner and outter networks)
*/
async getUnwrapTransactions ({ tokenSymbol, limit, page }) {
async getUnwrapTransactions ({ tokenSymbol, limit, page, userAddress = this.coinbase }) {
return new Promise((resolve, reject) => {
try {
let url = urljoin(
this.endpoint, 'api/transactions/getUnwrapTxs/',
`?address=${this.coinbase}`,
`?address=${userAddress}`,
`&page=${page}`,
`&limit=${limit}`
)
Expand Down Expand Up @@ -463,7 +467,6 @@ class BridgeJS {
txParams
)
let check = true, receipt
console.log('Verify tx...')
await sleep(5000)
while (check) {
receipt = await this.provider.getTransactionReceipt(result.hash || '')
Expand Down

0 comments on commit cf4841f

Please sign in to comment.