Skip to content

Commit

Permalink
Merge pull request #224 from Bitcoin-com/stage
Browse files Browse the repository at this point in the history
Remove address and scriptPubKey. Move scriptPubKey to the top level.
  • Loading branch information
cgcardona authored Jan 31, 2019
2 parents 090d912 + 8dc1668 commit 7b04448
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 35 deletions.
4 changes: 2 additions & 2 deletions dist/public/bitcoin-com-mainnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,8 @@
},
"openapi": "3.0.0",
"info": {
"description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com](https://developer.bitcoin.com). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.0",
"description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.1",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions dist/public/bitcoin-com-testnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,8 @@
},
"openapi": "3.0.0",
"info": {
"description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com](https://developer.bitcoin.com). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.0",
"description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.1",
"title": "REST",
"license": {
"name": "MIT",
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rest.bitcoin.com",
"version": "2.0.0",
"version": "2.0.1",
"description": "REST API for Bitcoin.com's Cloud",
"author": "Gabriel Cardona @ Bitcoin.com",
"contributors": [
Expand Down
29 changes: 18 additions & 11 deletions src/routes/v2/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ interface IRLConfig {
addressRateLimit3: any
addressRateLimit4: any
addressRateLimit5: any
addressRateLimit6: any
addressRateLimit7: any
addressRateLimit8: any
addressRateLimit9: any
}

const config: IRLConfig = {
Expand Down Expand Up @@ -159,7 +163,7 @@ async function detailsBulk(
logger.debug(`Executing address/details with these addresses: `, addresses)

// Validate each element in the address array.
for(let i=0; i < addresses.length; i++) {
for (let i = 0; i < addresses.length; i++) {
const thisAddress = addresses[i]

// Ensure the input is a valid BCH address.
Expand Down Expand Up @@ -289,11 +293,18 @@ async function utxoFromInsight(thisAddress: string) {
const retData = {
utxos: Array,
legacyAddress: String,
cashAddress: String
cashAddress: String,
scriptPubKey: String
}
retData.utxos = response.data
let spk = response.data[0].scriptPubKey
retData.legacyAddress = BITBOX.Address.toLegacyAddress(thisAddress)
retData.cashAddress = BITBOX.Address.toCashAddress(thisAddress)
retData.scriptPubKey = spk
retData.utxos = response.data.map((utxo: any) => {
delete utxo.address
delete utxo.scriptPubKey
return utxo
})
//console.log(`utxoFromInsight retData: ${util.inspect(retData)}`)

return retData
Expand Down Expand Up @@ -327,7 +338,7 @@ async function utxoBulk(
}

// Validate each element in the address array.
for(let i=0; i < addresses.length; i++) {
for (let i = 0; i < addresses.length; i++) {
const thisAddress = addresses[i]

// Ensure the input is a valid BCH address.
Expand Down Expand Up @@ -364,7 +375,6 @@ async function utxoBulk(

res.status(200)
return res.json(result)

} catch (err) {
// Attempt to decode the error message.
const { msg, status } = routeUtils.decodeError(err)
Expand Down Expand Up @@ -471,7 +481,7 @@ async function unconfirmedBulk(
}

// Validate each element in the address array.
for(let i=0; i < addresses.length; i++) {
for (let i = 0; i < addresses.length; i++) {
const thisAddress = addresses[i]

// Ensure the input is a valid BCH address.
Expand All @@ -495,7 +505,7 @@ async function unconfirmedBulk(
}

// Collect an array of promises.
const promises = addresses.map((address) => utxoFromInsight(address))
const promises = addresses.map(address => utxoFromInsight(address))

// Wait for all parallel Insight requests to return.
let result: Array<any> = await axios.all(promises)
Expand All @@ -517,7 +527,6 @@ async function unconfirmedBulk(
// Return the array of retrieved address information.
res.status(200)
return res.json(finalResult)

} catch (err) {
// Attempt to decode the error message.
const { msg, status } = routeUtils.decodeError(err)
Expand Down Expand Up @@ -653,7 +662,6 @@ async function transactionsBulk(
next: express.NextFunction
) {
try {

let addresses = req.body.addresses
const currentPage = req.body.page ? parseInt(req.body.page, 10) : 0

Expand All @@ -674,7 +682,7 @@ async function transactionsBulk(
}

// Validate each element in the address array.
for(let i=0; i < addresses.length; i++) {
for (let i = 0; i < addresses.length; i++) {
const thisAddress = addresses[i]

// Ensure the input is a valid BCH address.
Expand Down Expand Up @@ -708,7 +716,6 @@ async function transactionsBulk(
// Return the array of retrieved address information.
res.status(200)
return res.json(result)

} catch (err) {
// Attempt to decode the error message.
const { msg, status } = routeUtils.decodeError(err)
Expand Down
2 changes: 1 addition & 1 deletion swaggerJSONFiles/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"description": "",
"version": "2.0.0",
"version": "2.0.1",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions swaggerJSONFilesBuilt/mainnet/info.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"openapi": "3.0.0",
"info": {
"description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com](https://developer.bitcoin.com). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.0",
"description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.1",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions swaggerJSONFilesBuilt/testnet/info.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"openapi": "3.0.0",
"info": {
"description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com](https://developer.bitcoin.com). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.0",
"description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)",
"version": "2.0.1",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
25 changes: 18 additions & 7 deletions test/v2/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,17 @@ describe("#AddressRouter", () => {
assert.isArray(result, "result should be an array")

// Each element should have these primary properties.
assert.hasAllKeys(result[0], ["utxos", "legacyAddress", "cashAddress"])
assert.hasAllKeys(result[0], [
"utxos",
"legacyAddress",
"cashAddress",
"scriptPubKey"
])

// Validate the UTXO data structure.
assert.hasAnyKeys(result[0].utxos[0], [
"address",
"txid",
"vout",
"scriptPubKey",
"amount",
"satoshis",
"height",
Expand Down Expand Up @@ -704,14 +707,17 @@ describe("#AddressRouter", () => {
//console.log(`result: ${util.inspect(result)}`)

// Each element should have these primary properties.
assert.hasAllKeys(result, ["utxos", "legacyAddress", "cashAddress"])
assert.hasAllKeys(result, [
"utxos",
"legacyAddress",
"cashAddress",
"scriptPubKey"
])

// Validate the UTXO data structure.
assert.hasAnyKeys(result.utxos[0], [
"address",
"txid",
"vout",
"scriptPubKey",
"amount",
"satoshis",
"height",
Expand Down Expand Up @@ -949,7 +955,12 @@ describe("#AddressRouter", () => {
//console.log(`result: ${util.inspect(result)}`)

// Each element should have these primary properties.
assert.hasAllKeys(result, ["utxos", "legacyAddress", "cashAddress"])
assert.hasAllKeys(result, [
"utxos",
"legacyAddress",
"cashAddress",
"scriptPubKey"
])

assert.isArray(result.utxos)
})
Expand Down
6 changes: 0 additions & 6 deletions test/v2/mocks/address-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,24 @@ const mockAddressDetails = {

const mockUtxoDetails = [
{
address: "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W",
txid: "15f6a584080b04911121fbaca7bfcf3dd64ef2bfa5a01daf31e05a296c3e5e9e",
vout: 286,
scriptPubKey: "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac",
amount: 0.00001,
satoshis: 1000,
height: 546083,
confirmations: 3490
},
{
address: "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W",
txid: "15f6a584080b04911121fbaca7bfcf3dd64ef2bfa5a01daf31e05a296c3e5e9e",
vout: 287,
scriptPubKey: "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac",
amount: 0.00001,
satoshis: 1000,
height: 546083,
confirmations: 3490
},
{
address: "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W",
txid: "15f6a584080b04911121fbaca7bfcf3dd64ef2bfa5a01daf31e05a296c3e5e9e",
vout: 288,
scriptPubKey: "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac",
amount: 0.00001,
satoshis: 1000,
height: 546083,
Expand Down

0 comments on commit 7b04448

Please sign in to comment.