Skip to content

V8.0.0 Diff V6.0.0 #552

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

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
232761f
Putting all packages on v8.0.0
Apr 5, 2018
4b20481
Updating package locks after lerna bootstrap
Apr 5, 2018
020eb94
Adding docker and removing bitcore-build for now
Apr 6, 2018
70e1afd
Adding ports for bitcoin and ether nodes.
Apr 6, 2018
c9effb2
README update and using logger in db connect fail
Apr 6, 2018
3066c24
Adding trusted host environment variables, altering config to push th…
Apr 6, 2018
ff85337
Adding env config for different chains that can be passed in trough a…
Apr 6, 2018
142e480
Using checkArgument instead of copy and pasting this if statement
Apr 9, 2018
4d911fc
Adding broacast method to BTCStateProvider
Apr 9, 2018
d1b1580
Changing broadcast to use rpc
Apr 10, 2018
0a75a05
Merge commit '381dca4c64c2e30af66c2340ed5951836f9d89d3' into feature/…
Apr 10, 2018
dd69458
Merge commit '381dca4c64c2e30af66c2340ed5951836f9d89d3' into v8.0.0
Apr 10, 2018
5a9fad8
Adding spent to wallet-utxos and bitcore wallet client, and fixing bu…
Apr 10, 2018
7db3aae
Args missing on chain-state
Apr 10, 2018
c079b52
added missing params to handleReorg call
DanielRHayes Apr 10, 2018
cdc58b8
Merge branch 'fix/v8-add-chain-and-network-to-handleReorg-call' of gi…
nitsujlangston Apr 10, 2018
3c5c9ab
get rid of spread
nitsujlangston Apr 10, 2018
34f1fe1
more logging
nitsujlangston Apr 11, 2018
7831d70
Removing chain and network from WalletAddress
Apr 11, 2018
527a4c2
chain and network back on walletAddress
nitsujlangston Apr 12, 2018
8383438
Merge branch 'v8.0.0' of github.com:bitpay/bitcore into feature/v8-br…
Apr 12, 2018
6c7eab0
WIP
Apr 14, 2018
7cb6a3c
Adding wallet utils and authentication
nitsujlangston Apr 16, 2018
da421e8
Adding username/password to config and broadcast works now
Apr 16, 2018
949daf1
Adding username and password to config.js and singlequotes
Apr 16, 2018
9a34900
Simplify request signature verification
nitsujlangston Apr 16, 2018
190276d
Adding ability to load config from env, --config, and search home, bi…
Apr 16, 2018
3520f4d
Searching bitcore directory instead of packages directory
Apr 16, 2018
bb151c2
Breaking some logic into functions and making docker peer variables h…
Apr 17, 2018
cf52b6b
Merge branch 'feature/v8-config-resolution' into feature/v8-broadcast…
Apr 18, 2018
c86993e
Merging walletUtils and linking bitcore-mnemonic
Apr 18, 2018
f875e25
Merge branch 'feature/walletUtils' into feature/wallet-utils-bitcore-…
Apr 18, 2018
0e8cd49
Merge branch 'v8.0.0' of github.com:bitpay/bitcore into feature/walle…
nitsujlangston Apr 19, 2018
4df4d43
missed debug
nitsujlangston Apr 19, 2018
a96e950
Cleaning up missing :pubKey and removing walletId
Apr 20, 2018
2f912ff
changed order or priority for options in StorageService.start
DanielRHayes Apr 23, 2018
c646921
Adding authenticate and using req.wallet
Apr 24, 2018
1769fd2
Merge pull request #1523 from DanielRHayes/fix/bitcore-node/storage-s…
micahriggan Apr 24, 2018
e1989b9
Merge branch 'micahriggan-feature/walletUtils-create-tx' into v8.0.0
nitsujlangston Apr 25, 2018
5d399c1
Adding systemd service file
Apr 30, 2018
8f90ed1
Adding run script
May 1, 2018
1113e01
Adding chain and network to readme and adding start script
May 1, 2018
5cdb602
Merge commit '5d399c18d133b570e6908b8731a736bf7428d79f' into v8.0.0
May 1, 2018
d051efb
Fixing startup script
May 1, 2018
0bed6ac
adding commander to deps
nitsujlangston May 1, 2018
e5638c0
Merge branch 'v8.0.0' of github.com:bitpay/bitcore-node into v8.0.0
nitsujlangston May 1, 2018
92ca0fc
8.0.1
nitsujlangston May 2, 2018
7826864
Updating README with pubkey instead of walletId
May 2, 2018
e4110bb
README update
May 2, 2018
6e8143e
Merge commit '92ca0fccf7fc9cdc5d1772cee217ca551bfb3bfc' into v8.0.0
May 2, 2018
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
config.json
.bcoin
*bitcore.config.*
.bcoin
*.vscode
135 changes: 76 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,103 +8,120 @@ _Requirements_:

```
{
"pruneSpentScripts": true,
"chains": {
"BTC": {
"mainnet": {
"trustedPeers": [
{
"bitcoreNode": {
"pruneSpentScripts": true,
"chains": {
"BTC": {
"regtest": {
"chainSource": "p2p",
"trustedPeers": [
{
"host": "127.0.0.1",
"port": 30000
}
],
"rpc": {
"host": "127.0.0.1",
"port": 8333
"port": 30001,
"username": "bitpaytest",
"password": "local321"
}
]
}
},
"BCH": {
"mainnet": {
"parentChain": "BTC",
"forkHeight": 478558,
"trustedPeers": [
{
},
"testnet": {
"chainSource": "p2p",
"trustedPeers": [
{
"host": "127.0.0.1",
"port": 20000
}
],
"rpc": {
"host": "127.0.0.1",
"port": 9333
"port": 30001
}
]
}
}
}
}
}

```

# Wallet

## Add Wallet:
# Transactions

POST `/api/wallet`
## Get Transactions by block

BODY:
```
{
"name": "WalletName"
}
```
GET `/api/BTC/mainnet/tx/?blockHeight=123456`

## Get Wallet:
GET `/api/BTC/mainnet/tx/?blockHash=0000000000002917ed80650c6174aac8dfc46f5fe36480aaef682ff6cd83c3ca`

GET `/api/wallet/:walletId`
## Get Transaction by txid

## Import Addresses:
GET `/api/BTC/mainnet/tx/5c8a63e695caf95c28a0155beaa22b84a7adb18b8693ba90f04d94891d122afe`

POST `/api/wallet/:walletId`
# Address

BODY: raw jsonl wallet file of the form
```
{"address": "bItCoInAddReSSHeRe"}
```
## Get Transaction Outputs by Address

## Get Wallet Addresses
GET `/api/BTC/mainnet/address/mmEsgUprBEQkGDKowPQSLEYDbMtGRKxaF4/?unspent=true`

GET `/api/wallet/:walletId/addresses`
## Get Balance for an Address

## Get Wallet Transactions:
GET `/api/BTC/mainnet/address/mmEsgUprBEQkGDKowPQSLEYDbMtGRKxaF4/balance`

GET `/api/wallet/:walletId/transactions`
# Block

## Get Balance:
## Get Block

GET `/api/wallet/:walletId/balance`
GET `/api/BTC/mainnet/block/0000000000002917ed80650c6174aac8dfc46f5fe36480aaef682ff6cd83c3ca`

## Get Wallet UTXOS
GET `/api/BTC/mainnet/block/123456`

GET `/api/wallet/:walletId/utxos`

# Transactions
# Authenticated Methods
## Wallet

## Get Transactions by block
### Add Wallet:

GET `/api/BTC/mainnet/tx/?blockHeight=123456`
POST `/api/BTC/mainnet/wallet`

GET `/api/BTC/mainnet/tx/?blockHash=0000000000002917ed80650c6174aac8dfc46f5fe36480aaef682ff6cd83c3ca`
BODY:
```
{
"name": "WalletName",
"chain": "BTC",
"network": "mainnet",
"pubKey": "03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d",
"path": "m/44'/0'/0'"
}
```

## Get Transaction by txid
### Get Wallet:

GET `/api/BTC/mainnet/tx/5c8a63e695caf95c28a0155beaa22b84a7adb18b8693ba90f04d94891d122afe`
GET `/api/BTC/mainnet/wallet/:pubKey`

# Address
### Import Addresses:

## Get Transaction Outputs by Address
POST `/api/BTC/mainnet/wallet/:pubKey`

GET `/api/BTC/mainnet/address/mmEsgUprBEQkGDKowPQSLEYDbMtGRKxaF4/?unspent=true`
BODY: raw jsonl wallet file of the form
```
{"address": "bItCoInAddReSSHeRe"}
```

## Get Balance for an Address
### Get Wallet Addresses

GET `/api/BTC/mainnet/address/mmEsgUprBEQkGDKowPQSLEYDbMtGRKxaF4/balance`
GET `/api/BTC/mainnet/wallet/:pubKey/addresses`

# Block
### Get Wallet Transactions:

## Get Block
GET `/api/BTC/mainnet/wallet/:pubKey/transactions`

GET `/api/BTC/mainnet/block/0000000000002917ed80650c6174aac8dfc46f5fe36480aaef682ff6cd83c3ca`
### Get Balance:

GET `/api/BTC/mainnet/wallet/:pubKey/balance`

### Get Wallet UTXOS

GET `/api/BTC/mainnet/wallet/:pubKey/utxos`

GET `/api/BTC/mainnet/block/123456`
2 changes: 2 additions & 0 deletions bin/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../server.js');
11 changes: 11 additions & 0 deletions bitcore-node.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Bitcore Node
After=network.target

[Service]
User=bitcore
Group=bitcore
ExecStart=/usr/bin/node /home/bitcore/bitcore/packages/bitcore-node/server.js

[Install]
WantedBy=multi-user.target
87 changes: 69 additions & 18 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,84 @@
const Config = function(){
const os = require('os');
const program = require('commander');

program
.version('8.0.0')
.option('-c, --config <path>', 'The path to bitcore config')
.parse(process.argv);

function findConfig() {
let foundConfig;
const envConfigPath = process.env.BITCORE_CONFIG_PATH;
const argConfigPath = program.config;
const configFileName = 'bitcore.config.json';
let bitcoreConfigPaths = [
`${os.homedir()}/${configFileName}`,
`../../../${configFileName}`,
`../${configFileName}`
];
const overrideConfig = argConfigPath || envConfigPath;
if (overrideConfig) {
bitcoreConfigPaths.unshift(overrideConfig);
}
// No config specified. Search home, bitcore and cur directory
for (let path of bitcoreConfigPaths) {
if (!foundConfig) {
try {
const bitcoreConfig = require(path);
foundConfig = bitcoreConfig.bitcoreNode;
} catch (e) {
foundConfig = undefined;
}
}
}
return foundConfig;
}

function setTrustedPeers(config) {
for (let [chain, chainObj] of Object.entries(config.chains)) {
for (let network of Object.keys(chainObj)) {
let env = process.env;
const envString = `TRUSTED_${chain.toUpperCase()}_${network.toUpperCase()}_PEER`;
if (env[envString]) {
let peers = config.chains[chain][network].trustedPeers || [];
peers.push({
host: env[envString],
port: env[`${envString}_PORT`]
});
config.chains[chain][network].trustedPeers = peers;
}
}
}
return config;
}
const Config = function() {
let config = {
maxPoolSize: 20,
port: 3000,
dbHost: '127.0.0.1',
dbName: 'bitcore',
numWorkers: require('os').cpus().length,
dbHost: process.env.DB_HOST || '127.0.0.1',
dbName: process.env.DB_NAME || 'bitcore',
numWorkers: os.cpus().length,
chains: {}
};

let options;
try {
options = require('../config.json');
} catch(e) {
options = {};
}

Object.assign(config, options);
if (!Object.keys(config.chains).length){
let foundConfig = findConfig();
Object.assign(config, foundConfig, {});
if (!Object.keys(config.chains).length) {
config.chains.BTC = {
mainnet: {
chainSource: 'p2p',
trustedPeers: [
{ host: '127.0.0.1', port: 8333 }
]
trustedPeers: [{ host: '127.0.0.1', port: 8333 }],
rpc: {
host: '127.0.0.1',
port: 8332,
username: 'bitcoin',
password: 'bitcoin'
}
}
};
}

config = setTrustedPeers(config);
return config;
};

module.exports = new Config();
module.exports = new Config();
2 changes: 1 addition & 1 deletion lib/models/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ BlockSchema.statics.handleReorg = async function(params, callback) {
if (localTip.height === 0) {
return callback();
}
logger.info(`Resetting tip to ${localTip.previousBlockHash}`);
logger.info(`Resetting tip to ${localTip.previousBlockHash}`, { chain, network });
async.series([
function (cb) {
Block.remove({ chain, network, height: { $gte: localTip.height } }, cb);
Expand Down
13 changes: 7 additions & 6 deletions lib/models/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ TransactionSchema.statics.mintCoins = async function(params) {
try {
let wallets = await WalletAddress.collection
.find(
{ chain, network, address: { $in: mintOpsAddresses } },
{ address: { $in: mintOpsAddresses }, chain, network },
{ batchSize: 100 }
)
.toArray();
Expand Down Expand Up @@ -253,7 +253,7 @@ TransactionSchema.statics.spendCoins = function(params) {
let txid = tx._hash;
for (let input of tx.inputs) {
input = input.toObject();
spendOps.push({
const updateQuery = {
updateOne: {
filter: {
mintTxid: input.prevTxId,
Expand All @@ -263,16 +263,17 @@ TransactionSchema.statics.spendCoins = function(params) {
network
},
update: {
...(config.pruneSpentScripts && height > 0
? { $unset: { script: null } }
: {}),
$set: {
spentTxid: txid,
spentHeight: height
}
}
}
});
};
if (config.pruneSpentScripts && height > 0) {
updateQuery.updateOne.update.$unset = { script: null };
}
spendOps.push(updateQuery);
}
}
return spendOps;
Expand Down
4 changes: 3 additions & 1 deletion lib/models/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const WalletSchema = new Schema({
path: String
});

WalletSchema.index({ pubKey: 1 });

WalletSchema.statics._apiTransform = function (wallet, options) {
let transform = {
name: wallet.name,
Expand All @@ -24,7 +26,7 @@ WalletSchema.statics._apiTransform = function (wallet, options) {
WalletSchema.statics.updateCoins = async function (wallet) {
const WalletAddress = mongoose.model('WalletAddress');
let addresses = await WalletAddress.find({wallet: wallet._id});
return WalletAddress.updateCoins(wallet, addresses);
return WalletAddress.updateCoins({wallet, addresses});
};

module.exports = mongoose.model('Wallet', WalletSchema);
Loading