add blockchain install scripts
This commit is contained in:
parent
0e9e27b97b
commit
178f576cfb
39 changed files with 3938 additions and 750 deletions
|
|
@ -23,18 +23,27 @@ function fetch (account, method, params) {
|
|||
return r.data.result
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err.response.data.error)
|
||||
console.log(err.message)
|
||||
try {
|
||||
console.log(err.response.data.error)
|
||||
} catch (__) {}
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
function split (str) {
|
||||
const i = str.indexOf('=')
|
||||
if (i === -1) return []
|
||||
return [str.slice(0, i), str.slice(i + 1)]
|
||||
}
|
||||
|
||||
function parseConf (confPath) {
|
||||
const conf = fs.readFileSync(confPath)
|
||||
const lines = conf.toString().split('\n', 2)
|
||||
const lines = conf.toString().split('\n')
|
||||
|
||||
const res = {}
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const keyVal = lines[i].split('=')
|
||||
const keyVal = split(lines[i])
|
||||
|
||||
// skip when value is empty
|
||||
if (!keyVal[1]) continue
|
||||
|
|
|
|||
|
|
@ -39,11 +39,10 @@ function balance (account, cryptoCode) {
|
|||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
const confirmations = 1
|
||||
const bitcoins = cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)
|
||||
const coins = cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)
|
||||
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('sendfrom', [address, bitcoins, confirmations]))
|
||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||
.catch(err => {
|
||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||
throw err
|
||||
|
|
@ -103,10 +102,16 @@ function newFunding (account, cryptoCode) {
|
|||
}))
|
||||
}
|
||||
|
||||
function cryptoNetwork (account, cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => parseInt(rpcConfig.port, 10) === 18332 ? 'test' : 'main')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
balance,
|
||||
sendCoins,
|
||||
newAddress,
|
||||
getStatus,
|
||||
newFunding
|
||||
newFunding,
|
||||
cryptoNetwork
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,11 +103,17 @@ function newFunding (account, cryptoCode) {
|
|||
})
|
||||
}
|
||||
|
||||
function cryptoNetwork (account, cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => account.environment === 'test' ? 'test' : 'main')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
balance,
|
||||
sendCoins,
|
||||
newAddress,
|
||||
getStatus,
|
||||
newFunding
|
||||
newFunding,
|
||||
cryptoNetwork
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ module.exports = {
|
|||
sweep,
|
||||
defaultAddress,
|
||||
supportsHd: true,
|
||||
newFunding
|
||||
newFunding,
|
||||
privateKey
|
||||
}
|
||||
|
||||
if (!web3.isConnected()) {
|
||||
|
|
@ -31,6 +32,10 @@ if (!web3.isConnected()) {
|
|||
|
||||
const hex = bigNum => '0x' + bigNum.truncated().toString(16)
|
||||
|
||||
function privateKey (account) {
|
||||
return defaultWallet(account).getPrivateKey()
|
||||
}
|
||||
|
||||
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
|
||||
.then(_.tap(r => console.log('DEBUG113: %s', r)))
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ const rpcConfig = {
|
|||
port: config.rpcport || DEFAULT_PORT
|
||||
}
|
||||
|
||||
console.log('DEBUG101: %j', configPath)
|
||||
console.log('DEBUG100: %j', rpcConfig)
|
||||
|
||||
function fetch (method, params) {
|
||||
return jsonRpc.fetch(rpcConfig, method, params)
|
||||
}
|
||||
|
|
@ -40,11 +43,10 @@ function balance (account, cryptoCode) {
|
|||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
const confirmations = 1
|
||||
const bitcoins = cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)
|
||||
const coins = cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)
|
||||
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('sendfrom', [address, bitcoins, confirmations]))
|
||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||
.catch(err => {
|
||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||
throw err
|
||||
|
|
|
|||
|
|
@ -40,11 +40,10 @@ function balance (account, cryptoCode) {
|
|||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
const confirmations = 1
|
||||
const bitcoins = cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)
|
||||
const coins = cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)
|
||||
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('sendfrom', [address, bitcoins, confirmations]))
|
||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||
.catch(err => {
|
||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||
throw err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue