Compare commits

...
10 Commits
Author SHA1 Message Date
Chris Troutner 739bdf1f34 Merge pull request #17 from Permissionless-Software-Foundation/ct-unstable
fix(docs): Adding deploy script to automatically update documentation
2020-08-07 18:17:44 -07:00
Chris Troutner b207a1639e Removing unit test for SLP.Utils.balance() 2020-08-07 18:13:52 -07:00
Chris Troutner a169c0f7d0 fix(docs): Adding deploy script to automatically update documentation 2020-08-07 18:03:55 -07:00
Chris Troutner 65cf49adf0 Merge pull request #16 from Permissionless-Software-Foundation/zh
fix(electrumx): Added unconfirmed endpoint for Electrumx library.
2020-08-05 09:02:29 -07:00
Chris Troutner 65104d60ad Commented out failing integration tests 2020-08-05 08:54:54 -07:00
Chris Troutner fd0a1a6af2 editing api docs for electrumx 2020-08-05 08:47:04 -07:00
Chris Troutner 25299e2f6e Merge pull request #14 from zh/add-electrumx-unconfirmed-utxo
Access to unconfirmed UTXOs API endpoints
2020-08-05 08:42:14 -07:00
Stoyan Zhekov b184c080f1 Access to unconfirmed UTXOs API endpoints 2020-08-04 22:58:22 +09:00
Chris Troutner d2c999f739 Merge pull request #9 from Permissionless-Software-Foundation/ct-unstable
fix(Ninsight): Using POST endpoint only
2020-07-31 14:07:28 -07:00
Chris Troutner 4d2d8d0e5a fix(Ninsight): Using POST endpoint only 2020-07-31 14:04:22 -07:00
12 changed files with 346 additions and 101 deletions
+1 -1
View File
@@ -27,4 +27,4 @@ deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
- npx semantic-release && ./deploy-production.sh
+14
View File
@@ -0,0 +1,14 @@
# Triggers a webhook to update the staging server at staging.fullstack.cash.
#!/bin/bash
#echo $DEPLOY_SECRET
echo "Deploy to production...."
export DATA="{\"ref\":\"$DEPLOY_SECRET\"}"
#echo $DATA
curl -X POST http://fullstack.cash:9000/hooks/bch-js -H "Content-Type: application/json" -d $DATA
echo "...Finished deploying to production."
+95 -3
View File
@@ -24,7 +24,7 @@ class ElectrumX {
}
/**
* @api Electrumx.utxo() utxo() - Get a list of uxto for an address.
* @api Electrumx.utxo() utxo()
* @apiName ElectrumX Utxo
* @apiGroup ElectrumX
* @apiDescription Return a list of uxtos for an address.
@@ -119,7 +119,7 @@ class ElectrumX {
}
/**
* @api Electrumx.balance() balance() - Get the balance for an address.
* @api Electrumx.balance() balance()
* @apiName ElectrumX Balance
* @apiGroup ElectrumX
* @apiDescription Return a list of balances for an address.
@@ -203,7 +203,7 @@ class ElectrumX {
}
/**
* @api Electrumx.transactions() transactions() - Get the transaction history for an address.
* @api Electrumx.transactions() transactions()
* @apiName ElectrumX Transactions
* @apiGroup ElectrumX
* @apiDescription Return a transaction history for an address.
@@ -299,6 +299,98 @@ class ElectrumX {
else throw error
}
}
/**
* @api Electrumx.unconfirmed() unconfirmed()
* @apiName ElectrumX Unconfirmed
* @apiGroup ElectrumX
* @apiDescription Return a list of unconfirmed uxtos (mempool) for an address.
*
* @apiExample Example usage:
* (async () => {
* try {
* let mempool = await bchjs.Electrumx.unconfirmed('bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9');
* console.log(mempool);
* } catch(error) {
* console.error(error)
* }
* })()
*
* mempool = {
* "success": true,
* "utxos": [
* {
* "height": 602405,
* "tx_hash": "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7",
* "fee": 24310
* }
* ]
* }
*
* (async () => {
* try {
* let mempool = await bchjs.Electrumx.unconfirmed(['bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v']);
* console.log(mempool);
* } catch(error) {
* console.error(error)
* }
* })()
*
* mempool = {
* "success": true,
* "utxos": [
* {
* "utxos": [
* {
* "height": 604392,
* "tx_hash": "7774e449c5a3065144cefbc4c0c21e6b69c987f095856778ef9f45ddd8ae1a41",
* "fee": 24310
* },
* {
* "height": 630834,
* "tx_hash": "4fe60a51e0d8f5134bfd8e5f872d6e502d7f01b28a6afebb27f4438a4f638d53",
* "fee": 3000
* }
* ],
* "address": "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"
* },
* {
* "utxos": [],
* "address": "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v"
* }
* ]
* }
*
*/
async unconfirmed(address) {
try {
// Handle single address.
if (typeof address === "string") {
const response = await axios.get(
`${this.restURL}electrumx/unconfirmed/${address}`,
_this.axiosOptions
)
return response.data
// Handle array of addresses.
} else if (Array.isArray(address)) {
const response = await axios.post(
`${this.restURL}electrumx/unconfirmed`,
{
addresses: address
},
_this.axiosOptions
)
return response.data
}
throw new Error(`Input address must be a string or array of strings.`)
} catch (error) {
if (error.response && error.response.data) throw error.response.data
else throw error
}
}
}
module.exports = ElectrumX
+4 -1
View File
@@ -68,8 +68,11 @@ class Ninsight {
try {
// Handle single address.
if (typeof address === "string") {
const response = await axios.get(
const response = await axios.post(
`${this.ninsightURL}/address/utxo/${address}`,
{
addresses: [address]
},
_this.axiosOptions
)
return response.data
-78
View File
@@ -370,84 +370,6 @@ class Utils {
}
}
/**
* @api SLP.Utils.balance() balance()
* @apiName balance
* @apiGroup SLP Utils
* @apiDescription Return single balance for an address by token id.
*
* @apiExample Example usage:
*
* // single balance for SLP Address
* (async () => {
* try {
* let balance = await bchjs.SLP.Utils.balance(
* "simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk",
* "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb"
* );
* console.log(balance);
* } catch (error) {
* console.error(error);
* }
* })();
*
* // returns
* // { tokenId:
* // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
* // balance: '617',
* // decimalCount: 8 }
*
* // single balance for Cash Address
* (async () => {
* try {
* let balance = await bchjs.SLP.Utils.balance(
* "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg",
* "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb"
* );
* console.log(balance);
* } catch (error) {
* console.error(error);
* }
* })();
*
* // returns
* // { tokenId:
* // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
* // balance: '617',
* // decimalCount: 8 }
*
* // single balance for Legacy Address
* (async () => {
* try {
* let balance = await bchjs.SLP.Utils.balance(
* "1DwQqpWc8pzaRydCmiJsPdoqCzmjSQQbp8",
* "467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5"
* );
* console.log(balance);
* } catch (error) {
* console.error(error);
* }
* })();
*
* // returns
* // { tokenId:
* // '467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5',
* // balance: '1234',
* // decimalCount: 2 }
*/
// Retrieve a balance for a specific address and token ID
async balance(address, tokenId) {
const path = `${this.restURL}slp/balance/${address}/${tokenId}`
try {
const response = await axios.get(path, _this.axiosOptions)
return response.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
throw error
}
}
/**
* @api SLP.Utils.validateTxid() validateTxid()
* @apiName validateTxid
+62
View File
@@ -178,4 +178,66 @@ describe(`#ElectrumX`, () => {
}
})
})
describe(`#unconfirmed`, () => {
// These tests won't work because unconfirmed transactions are transient in nature.
/*
it(`should GET unconfirmed UTXOs (mempool) for a single address`, async () => {
const addr = "bitcoincash:qqy6qwk3wpne95hhv8uzwr4cn8m7c06cqgchl77dnv"
const result = await bchjs.Electrumx.unconfirmed(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "success")
assert.equal(result.success, true)
assert.property(result, "utxos")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "height")
assert.property(result.utxos[0], "tx_hash")
assert.property(result.utxos[0], "fee")
})
it(`should POST request for unconfirmed UTXOs (mempool) for an array of addresses`, async () => {
const addr = [
"bitcoincash:qqy6qwk3wpne95hhv8uzwr4cn8m7c06cqgchl77dnv",
"bitcoincash:qpyrtsl9msdu2klgfpcmn2v5r22w9rk24g8pal74ts"
]
const result = await bchjs.Electrumx.unconfirmed(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "success")
assert.equal(result.success, true)
assert.property(result, "utxos")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "utxos")
assert.isArray(result.utxos[0].utxos)
assert.property(result.utxos[0], "address")
assert.property(result.utxos[0].utxos[0], "height")
assert.property(result.utxos[0].utxos[0], "tx_hash")
assert.property(result.utxos[0].utxos[0], "fee")
})
*/
it(`should throw error on array size rate limit`, async () => {
try {
const addr = []
for (let i = 0; i < 25; i++)
addr.push("bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf")
await bchjs.Electrumx.unconfirmed(addr)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(true, false, "Unexpected result!")
} catch (err) {
assert.hasAnyKeys(err, ["error"])
assert.include(err.error, "Array too large")
}
})
})
})
+62
View File
@@ -182,4 +182,66 @@ describe(`#ElectrumX`, () => {
}
})
})
describe(`#unconfirmed`, () => {
// These tests won't work because unconfirmed transactions are transient in nature.
/*
it(`should GET unconfirmed UTXOs (mempool) for a single address`, async () => {
const addr = "bchtest:qp25k20dgcljrz4hkdz43partam3j5httyprjp23qd"
const result = await bchjs.Electrumx.unconfirmed(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "success")
assert.equal(result.success, true)
assert.property(result, "utxos")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "height")
assert.property(result.utxos[0], "tx_hash")
assert.property(result.utxos[0], "fee")
})
it(`should POST unconfirmed UTXO details for an array of addresses`, async () => {
const addr = [
"bchtest:qp25k20dgcljrz4hkdz43partam3j5httyprjp23qd",
"bchtest:qpkl3xylrjx4jup6m66e7zg7whlaucsxeudxeqawdj"
]
const result = await bchjs.Electrumx.unconfirmed(addr)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "success")
assert.equal(result.success, true)
assert.property(result, "utxos")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "utxos")
assert.isArray(result.utxos[0].utxos)
assert.property(result.utxos[0], "address")
assert.property(result.utxos[0].utxos[0], "height")
assert.property(result.utxos[0].utxos[0], "tx_hash")
assert.property(result.utxos[0].utxos[0], "fee")
})
*/
it(`should throw error on array size rate limit`, async () => {
try {
const addr = []
for (let i = 0; i < 25; i++)
addr.push("bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2")
await bchjs.Electrumx.unconfirmed(addr)
//console.log(`result: ${util.inspect(result)}`)
assert.equal(true, false, "Unexpected result!")
} catch (err) {
assert.hasAnyKeys(err, ["error"])
assert.include(err.error, "Array too large")
}
})
})
})
@@ -6,3 +6,4 @@ export NETWORK=testnet
cd test/integration/testnet/
mocha --timeout 30000 blockchain.js control.js electrumx.js openbazaar.js rawtransaction.js slp.js util.js
#mocha --timeout 30000 blockchain.js
+64
View File
@@ -196,4 +196,68 @@ describe(`#ElectrumX`, () => {
assert.property(result.transactions[0].transactions[0], "tx_hash")
})
})
describe(`#unconfirmed`, () => {
it(`should throw an error for improper input`, async () => {
try {
const addr = 12345
await bchjs.Electrumx.unconfirmed(addr)
assert.equal(true, false, "Unexpected result!")
} catch (err) {
// console.log(`err: `, err)
assert.include(
err.message,
`Input address must be a string or array of strings`
)
}
})
it(`should GET unconfirmed utxos for a single address`, async () => {
// Stub the network call.
sandbox.stub(axios, "get").resolves({ data: mockData.unconfirmed })
const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"
const result = await bchjs.Electrumx.unconfirmed(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "success")
assert.equal(result.success, true)
assert.property(result, "utxos")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "height")
assert.property(result.utxos[0], "tx_hash")
assert.property(result.utxos[0], "fee")
})
it(`should POST unconfirmed utxo details for an array of addresses`, async () => {
// Stub the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.unconfirmedArray })
const addr = [
"bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf",
"bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v"
]
const result = await bchjs.Electrumx.unconfirmed(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "success")
assert.equal(result.success, true)
assert.property(result, "utxos")
assert.isArray(result.utxos)
assert.property(result.utxos[0], "utxos")
assert.isArray(result.utxos[0].utxos)
assert.property(result.utxos[0], "address")
assert.property(result.utxos[0].utxos[0], "height")
assert.property(result.utxos[0].utxos[0], "tx_hash")
assert.property(result.utxos[0].utxos[0], "fee")
})
})
})
+42 -1
View File
@@ -119,11 +119,52 @@ const transactions = {
]
}
const unconfirmed = {
success: true,
utxos: [
{
height: 602405,
tx_hash:
"2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7",
fee: 34100
}
]
}
const unconfirmedArray = {
success: true,
utxos: [
{
utxos: [
{
height: 604392,
tx_hash:
"7774e449c5a3065144cefbc4c0c21e6b69c987f095856778ef9f45ddd8ae1a41",
fee: 34210
},
{
height: 630834,
tx_hash:
"4fe60a51e0d8f5134bfd8e5f872d6e502d7f01b28a6afebb27f4438a4f638d53",
value: 3000
}
],
address: "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"
},
{
utxos: [],
address: "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v"
}
]
}
module.exports = {
utxo,
utxos,
balance,
balances,
transaction,
transactions
transactions,
unconfirmed,
unconfirmedArray
}
+1 -1
View File
@@ -31,7 +31,7 @@ describe(`#Ninsight`, () => {
it(`should GET utxos for a single address`, async () => {
// Stub the network call.
sandbox.stub(axios, "get").resolves({ data: mockData.utxo })
sandbox.stub(axios, "post").resolves({ data: mockData.utxo })
const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"
-16
View File
@@ -231,22 +231,6 @@ describe("#SLP Utils", () => {
})
})
describe("#balance", () => {
it(`should fetch balance of single token for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9`, async () => {
// Mock the call to the REST API
if (process.env.TEST === "unit")
sandbox.stub(axios, "get").resolves({ data: mockData.mockBalance })
const balance = await slp.Utils.balance(
"simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9",
"df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb"
)
//console.log(`balance: ${JSON.stringify(balance, null, 2)}`)
assert2.hasAllKeys(balance, ["tokenId", "balance", "balanceString"])
})
})
describe("#validateTxid", () => {
it(`should validate slp txid`, async () => {
// Mock the call to the REST API