use https://api.dcousens.cloud reg-test server instead of testnet
This commit is contained in:
parent
f3cc30de87
commit
4ca6bf4e81
8 changed files with 303 additions and 315 deletions
test/integration
78
test/integration/_regtest.js
Normal file
78
test/integration/_regtest.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
var bitcoin = require('../../')
|
||||
var dhttp = require('dhttp/200')
|
||||
|
||||
var APIPASS = process.env.APIPASS || 'satoshi'
|
||||
var APIURL = 'https://api.dcousens.cloud/1'
|
||||
|
||||
function broadcast (txHex, callback) {
|
||||
dhttp({
|
||||
method: 'PUT',
|
||||
url: APIURL + '/t/push',
|
||||
body: txHex
|
||||
}, callback)
|
||||
}
|
||||
|
||||
function mine (count, callback) {
|
||||
dhttp({
|
||||
method: 'POST',
|
||||
url: APIURL + '/r/generate?count=' + count + '&key=' + APIPASS
|
||||
}, callback)
|
||||
}
|
||||
|
||||
function faucet (address, value, callback) {
|
||||
dhttp({
|
||||
method: 'POST',
|
||||
url: APIURL + '/r/faucet?address=' + address + '&value=' + value + '&key=' + APIPASS
|
||||
}, function (err, txId) {
|
||||
if (err) return callback(err)
|
||||
|
||||
unspents(address, function (err, results) {
|
||||
if (err) return callback(err)
|
||||
|
||||
callback(null, results.filter(x => x.txId === txId).pop())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function fetch (txId, callback) {
|
||||
dhttp({
|
||||
method: 'GET',
|
||||
url: APIURL + '/t/' + txId
|
||||
}, callback)
|
||||
}
|
||||
|
||||
function unspents (address, callback) {
|
||||
dhttp({
|
||||
method: 'GET',
|
||||
url: APIURL + '/a/' + address + '/unspents'
|
||||
}, callback)
|
||||
}
|
||||
|
||||
function verify (txo, callback) {
|
||||
let { txId } = txo
|
||||
|
||||
fetch(txId, function (err, txHex) {
|
||||
if (err) return callback(err)
|
||||
|
||||
// TODO: verify address and value
|
||||
callback()
|
||||
})
|
||||
}
|
||||
|
||||
function randomAddress () {
|
||||
return bitcoin.ECPair.makeRandom({
|
||||
network: bitcoin.networks.testnet
|
||||
}).getAddress()
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
broadcast: broadcast,
|
||||
faucet: faucet,
|
||||
fetch: fetch,
|
||||
mine: mine,
|
||||
network: bitcoin.networks.testnet,
|
||||
unspents: unspents,
|
||||
verify: verify,
|
||||
randomAddress: randomAddress,
|
||||
RANDOM_ADDRESS: randomAddress()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue