Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auc 560 #12

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ For CENTOS
RUN yum install -y make gcc*
```

#### Yarn

For Ubuntu
```
import GPG and add yarn repo

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
```
```
sudo apt update
sudo apt install --no-install-recommends yarn
```

### Full node

Fire up a full Bitcoin Cash node and add the following to your `bitcoin.conf`.
Expand Down Expand Up @@ -89,6 +103,7 @@ git clone https://github.com/Bitcoin-com/rest.bitcoin.com.git
```
cd rest.bitcoin.com
npm install
yarn
```

#### Build REST
Expand Down Expand Up @@ -125,6 +140,11 @@ Starting in the regtest mode (partly working since the bitcoincom_baseurl does n
PORT=3000 BITCOINCOM_BASEURL=http://localhost:3000/api/ RPC_BASEURL=http://localhost:18332/ RPC_PASSWORD=regtest RPC_USERNAME=regtest ZEROMQ_PORT=0 ZEROMQ_URL=0 NETWORK=local npm start
```

#### Run Tests
```
npm run test
```

#### View in browser

Finally open `http://localhost:3000/` and confirm you see the GUI
27 changes: 6 additions & 21 deletions src/routes/v2/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,8 @@ async function detailsFromInsight(
): Promise<AddressDetailsInterface> {
try {
let addr: string
if (
process.env.BITCOINCOM_BASEURL === "https://bch-insight.bitpay.com/api/"
) {
addr = bitbox.Address.toCashAddress(thisAddress)
} else {
addr = bitbox.Address.toLegacyAddress(thisAddress)
}

addr = bitbox.Address.toCashAddress(thisAddress, true, isRegtest)

let path: string = `${process.env.BITCOINCOM_BASEURL}addr/${addr}`

Expand Down Expand Up @@ -273,13 +268,8 @@ async function utxoFromInsight(
): Promise<AddressUTXOsInterface> {
try {
let addr: string
if (
process.env.BITCOINCOM_BASEURL === "https://bch-insight.bitpay.com/api/"
) {
addr = Utils.toCashAddress(thisAddress)
} else {
addr = Utils.toLegacyAddress(thisAddress)
}

addr = bitbox.Address.toCashAddress(thisAddress, true, isRegtest)

const path: string = `${process.env.BITCOINCOM_BASEURL}addr/${addr}/utxo`

Expand Down Expand Up @@ -661,13 +651,8 @@ async function transactionsFromInsight(
): Promise<TransactionsInterface> {
try {
let addr: string
if (
process.env.BITCOINCOM_BASEURL === "https://bch-insight.bitpay.com/api/"
) {
addr = Utils.toCashAddress(thisAddress)
} else {
addr = Utils.toLegacyAddress(thisAddress)
}

addr = bitbox.Address.toCashAddress(thisAddress, true, isRegtest)

const path: string = `${process.env.BITCOINCOM_BASEURL}txs/?address=${addr}&pageNum=${currentPage}`

Expand Down
36 changes: 18 additions & 18 deletions test/v2/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)
}

Expand All @@ -210,7 +210,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=5000&to=6000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=5000&to=6000`)
.reply(200, mockData.mockAddressDetails)
}

Expand All @@ -230,7 +230,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)
}

Expand All @@ -249,7 +249,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)
}

Expand Down Expand Up @@ -290,11 +290,11 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)

nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mwJnEzXzKkveF2q5Af9jxi9j1zrtWAnPU8?from=0&to=1000`)
.get(`/addr/bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)
}

Expand Down Expand Up @@ -382,7 +382,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)
}

Expand All @@ -401,7 +401,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=5000&to=6000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=5000&to=6000`)
.reply(200, mockData.mockAddressDetails)
}

Expand All @@ -418,7 +418,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)
}

Expand All @@ -434,7 +434,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz?from=0&to=1000`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4?from=0&to=1000`)
.reply(200, mockData.mockAddressDetails)
}

Expand Down Expand Up @@ -554,7 +554,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4/utxo`)
.reply(200, mockData.mockUtxoDetails)
}

Expand Down Expand Up @@ -596,11 +596,11 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4/utxo`)
.reply(200, mockData.mockUtxoDetails)

nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mwJnEzXzKkveF2q5Af9jxi9j1zrtWAnPU8/utxo`)
.get(`/addr/bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr/utxo`)
.reply(200, mockData.mockUtxoDetails)
}

Expand Down Expand Up @@ -701,7 +701,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4/utxo`)
.reply(200, mockData.mockUtxoDetails)
}

Expand Down Expand Up @@ -834,7 +834,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4/utxo`)
.reply(200, mockData.mockUtxoDetails)
}

Expand All @@ -861,11 +861,11 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4/utxo`)
.reply(200, mockData.mockUtxoDetails)

nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mwJnEzXzKkveF2q5Af9jxi9j1zrtWAnPU8/utxo`)
.get(`/addr/bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr/utxo`)
.reply(200, mockData.mockUtxoDetails)
}

Expand Down Expand Up @@ -951,7 +951,7 @@ describe("#AddressRouter", () => {
// Mock the Insight URL for unit tests.
if (process.env.TEST === "unit") {
nock(`${process.env.BITCOINCOM_BASEURL}`)
.get(`/addr/mgps7qxk2Z5ma4mXsviznnet8wx4VvMPFz/utxo`)
.get(`/addr/bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4/utxo`)
.reply(200, mockData.mockUtxoDetails)
}

Expand Down
18 changes: 7 additions & 11 deletions test/v2/slp.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,20 +769,16 @@ describe("#SLP", () => {
})

it("should error on malformed address", async () => {
try {
req.body.addresses = ["bitcoincash:qzs02v05l7qs5s5dwuj0cx5ehjm2c"]

await convertAddressBulk(req, res)
req.body.addresses = ["bitcoincash:qzs02v05l7qs5s5dwuj0cx5ehjm2c"]

assert.equal(true, false, "Unexpected result.")
} catch (err) {
// console.log(`err.message: ${util.inspect(err.message)}`)
const result = await convertAddressBulk(req, res)

assert.include(
err.message,
`Invalid BCH address. Double check your address`
)
}
assert.hasAllKeys(result, ["error"])
assert.include(
result.error,
`Invalid BCH address. Double check your address`
)
})

it("should validate array with single element", async () => {
Expand Down