Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/bitcore-wallet-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"bitcore-lib-cash": "^8.6.0",
"body-parser": "^1.11.0",
"compression": "^1.6.2",
"crypto-wallet-core": "^8.6.0",
"email-validator": "^1.0.1",
"express": "^4.10.0",
"express-rate-limit": "^2.6.0",
Expand Down
10 changes: 8 additions & 2 deletions packages/bitcore-wallet-service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ module.exports = {
url: 'https://api.bitcore.io',
},
testnet: {
// url: 'http://localhost:3000',
url: 'https://api.bitcore.io',
},

},
eth: {
livenet: {
url: 'https://api.bitcore.io',
},
testnet: {
url: 'https://api.bitcore.io',
},
},
},
pushNotificationsOpts: {
Expand Down
4 changes: 4 additions & 0 deletions packages/bitcore-wallet-service/src/lib/blockchainexplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const PROVIDERS = {
bch: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
},
eth: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
}
}
};
Expand Down
33 changes: 31 additions & 2 deletions packages/bitcore-wallet-service/src/lib/blockchainexplorers/v8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const BCHAddressTranslator = require('../bchaddresstranslator');
const Bitcore = require('bitcore-lib');
const Bitcore_ = {
btc: Bitcore,
bch: require('bitcore-lib-cash')
bch: require('bitcore-lib-cash'),
eth: Bitcore
};
const config = require('../../config');
const Constants = Common.Constants,
Expand Down Expand Up @@ -355,6 +356,34 @@ export class V8 {
});
}

getTransactionCount(address, cb) {
const url = this.baseUrl + '/address/' + address + '/txs/count';
console.log('[v8.js.364:url:] CHECKING ADDRESS NONCE', url);
this.request
.get(url, {})
.then(ret => {
ret = JSON.parse(ret);
return cb(null, ret.nonce);
})
.catch(err => {
return cb(err);
});
}

estimateGas(opts, cb) {
const url = this.baseUrl + '/fee/gas';
console.log('[v8.js.378:url:] CHECKING GAS LIMIT', url);
this.request
.post(url, { body: opts, json: true })
.then(gasLimit => {
gasLimit = JSON.parse(gasLimit);
return cb(null, gasLimit);
})
.catch(err => {
return cb(err);
});
}

estimateFee(nbBlocks, cb) {
nbBlocks = nbBlocks || [1, 2, 6, 24];
const result = {};
Expand All @@ -375,7 +404,7 @@ export class V8 {
return icb();
}

result[x] = ret.feerate;
result[x] = ret.feerate ? ret.feerate : ret;
} catch (e) {
log.warn('fee error:', e);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/bitcore-wallet-service/src/lib/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

module.exports = {
COINS: {
BTC: 'btc',
BCH: 'bch',
ETH: 'eth'
},

UTXO_COINS: {
BTC: 'btc',
BCH: 'bch'
},
Expand Down
30 changes: 30 additions & 0 deletions packages/bitcore-wallet-service/src/lib/common/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
MAX_TX_FEE: 0.1 * 1e8,
MAX_TX_SIZE_IN_KB: 100,

// ETH
DEFAULT_GAS_LIMIT: 21000,

MAX_KEYS: 100,

// Time after which a tx proposal can be erased by any copayer. in seconds
Expand Down Expand Up @@ -58,6 +61,33 @@ module.exports = {
nbBlocks: 2,
defaultValue: 2000
}
],
eth: [
{
name: 'urgent',
nbBlocks: 10, // < 2 min
defaultValue: 3000000000
},
{
name: 'priority',
nbBlocks: 15, // 3 min
defaultValue: 2000000000
},
{
name: 'normal',
nbBlocks: 25, // 5 min
defaultValue: 1000000000
},
{
name: 'economy',
nbBlocks: 50, // 10 minutes
defaultValue: 1000000000
},
{
name: 'superEconomy',
nbBlocks: 75, // 15 minutes
defaultValue: 1000000000
}
]
},

Expand Down
7 changes: 6 additions & 1 deletion packages/bitcore-wallet-service/src/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ export class Utils {
toSatoshis: 100000000,
maxDecimals: 6,
minDecimals: 2
}
},
eth: {
toSatoshis: 1e18,
maxDecimals: 6,
minDecimals: 2
},
};

$.shouldBeNumber(satoshis);
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-wallet-service/src/lib/fiatrateservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class FiatRateService {

_fetch(cb?) {
cb = cb || function() { };
const coins = ['btc', 'bch'];
const coins = ['btc', 'bch', 'eth'];
const provider = this.providers[0];

// async.each(this.providers, (provider, next) => {
Expand Down
34 changes: 27 additions & 7 deletions packages/bitcore-wallet-service/src/lib/model/address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Deriver } from 'crypto-wallet-core';
import _ from 'lodash';
import { AddressManager } from './addressmanager';

const $ = require('preconditions').singleton();
const Common = require('../common');
Expand Down Expand Up @@ -56,8 +58,10 @@ export class Address {
x.publicKeys = opts.publicKeys;
x.coin = opts.coin;
x.network = Address.Bitcore[opts.coin]
.Address(x.address)
.toObject().network;
? Address.Bitcore[opts.coin]
.Address(x.address)
.toObject().network
: opts.network;
x.type = opts.type || Constants.SCRIPT_TYPES.P2SH;
x.hasActivity = undefined;
x.beRegistered = null;
Expand Down Expand Up @@ -96,7 +100,9 @@ export class Address {
);

const publicKeys = _.map(publicKeyRing, (item) => {
const xpub = new Address.Bitcore[coin].HDPublicKey(item.xPubKey);
const xpub = Address.Bitcore[coin]
? new Address.Bitcore[coin].HDPublicKey(item.xPubKey)
: new Address.Bitcore.btc.HDPublicKey(item.xPubKey);
return xpub.deriveChild(path).publicKey;
});

Expand All @@ -111,10 +117,23 @@ export class Address {
break;
case Constants.SCRIPT_TYPES.P2PKH:
$.checkState(_.isArray(publicKeys) && publicKeys.length == 1);
bitcoreAddress = Address.Bitcore[coin].Address.fromPublicKey(
publicKeys[0],
network
);

if (Address.Bitcore[coin]) {
bitcoreAddress = Address.Bitcore[coin].Address.fromPublicKey(
publicKeys[0],
network
);
} else {
const { addressIndex, isChange } = new AddressManager().parseDerivationPath(path);
const [{ xPubKey }] = publicKeyRing;
bitcoreAddress = Deriver.deriveAddress(
coin.toUpperCase(),
network,
xPubKey,
addressIndex,
isChange
);
}
break;
}

Expand Down Expand Up @@ -155,6 +174,7 @@ export class Address {
return Address.create(
_.extend(raw, {
coin,
network,
walletId,
type: scriptType,
isChange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,11 @@ export class AddressManager {
const ret = this.skippedPaths.pop();
return ret;
}

parseDerivationPath(path) {
const pathIndex = /m\/([0-9]*)\/([0-9]*)/;
const [_input, changeIndex, addressIndex] = path.match(pathIndex);
const isChange = changeIndex > 0;
return { _input, addressIndex, isChange };
}
}
Loading