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

Chain state provider + Currency Routes + Tests #15

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
739c7ec
Initial chain-state providers efforts
Mar 21, 2018
4bf7218
WIP
Mar 21, 2018
4eb942b
Got address utxos working
Mar 21, 2018
77da89c
get address balance works
Mar 21, 2018
9b4d8a2
get balance for address works
Mar 21, 2018
074c398
get wallet works
Mar 21, 2018
f739fd1
Get wallet addresses works
Mar 21, 2018
4f86ba6
Get wallet transactions runs without errors... needs testing
Mar 21, 2018
8ed885f
Get wallet transactions works
Mar 21, 2018
c50fd9d
Actually, I'll leave this and have J look at it
Mar 21, 2018
372538d
Get wallet balance works now
Mar 21, 2018
abfcf8e
Get wallet utxos works
Mar 21, 2018
96692e4
Remvoing findOne and using getWallet through ChainStateProvider
Mar 21, 2018
13562ad
indentation
Mar 21, 2018
8563737
create and update wallet
Mar 22, 2018
40148a4
Get block works
Mar 22, 2018
faf3377
reverting package.json
Mar 22, 2018
fa1f630
Using req.params for chain and network
Mar 23, 2018
0004bf6
reverting find to findOne
Mar 23, 2018
42874d3
Adding tests for api abstraction
Mar 26, 2018
2d6f9b1
Merge pull request #2 from micahriggan/feature/api-abstraction
micahriggan Mar 26, 2018
5701db0
Removing this file
Mar 26, 2018
439bee1
Merge branch 'master' of github.com:nitsujlangston/fullNodePlus into …
Mar 26, 2018
207fcd6
Server.js merge messed up
Mar 26, 2018
797ca41
Network filter was broken after abstraction
Mar 26, 2018
a7832de
Fixed logic to allow multiple networks in config
Mar 26, 2018
438a6a7
Changing getTransaction to streamTransaction
Mar 27, 2018
28fade9
Updating getX to streamX where method writes to a stream
Mar 27, 2018
eb86298
Removing async
Mar 27, 2018
0222391
Adding nosync to config to skip p2p
Mar 27, 2018
17957f9
Streaming address UTXOs
Mar 27, 2018
9c4b80b
using chainSource from config
Mar 27, 2018
4014977
Fixing null block error and simplifying chainSource logic
Mar 27, 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
Prev Previous commit
Next Next commit
Get wallet transactions runs without errors... needs testing
Micah Riggan committed Mar 21, 2018
commit 4f86ba60e59812339de19adf6e6f5a65a8db318d
34 changes: 18 additions & 16 deletions lib/providers/chain-state/btc/btc.js
Original file line number Diff line number Diff line change
@@ -105,27 +105,29 @@ BTCStateProvider.prototype.getWalletAddresses = async function(network, walletId
Storage.apiStreamingFind(WalletAddress, query, stream);
};

BTCStateProvider.prototype.updateWallet = async function(chain, walletId, addresses) {
BTCStateProvider.prototype.updateWallet = async function(network, walletId, addresses) {
return WalletAddress.updateCoins(walletId, addresses);
};

BTCStateProvider.prototype.getWalletTransactions = async function(walletId, stream, args) {
BTCStateProvider.prototype.getWalletTransactions = async function(network, walletId, stream, args) {
let query = {
wallets: walletId
};
if (args.startBlock) {
query.blockHeight = { $gte: parseInt(args.startBlock) };
}
if (args.endBlock) {
query.blockHeight = query.blockHeight || {};
query.blockHeight.$lte = parseInt(args.endBlock);
}
if (args.startDate) {
query.blockTimeNormalized = { $gte: new Date(args.startDate) };
}
if (args.endDate) {
query.blockTimeNormalized = query.blockTimeNormalized || {};
query.blockTimeNormalized.$lt = new Date(args.endDate);
if(args) {
if (args.startBlock) {
query.blockHeight = { $gte: parseInt(args.startBlock) };
}
if (args.endBlock) {
query.blockHeight = query.blockHeight || {};
query.blockHeight.$lte = parseInt(args.endBlock);
}
if (args.startDate) {
query.blockTimeNormalized = { $gte: new Date(args.startDate) };
}
if (args.endDate) {
query.blockTimeNormalized = query.blockTimeNormalized || {};
query.blockTimeNormalized.$lt = new Date(args.endDate);
}
}
let transactionStream = Transaction.getTransactions({query});
let listTransactionsStream = new ListTransactionsStream(walletId);
@@ -146,7 +148,7 @@ BTCStateProvider.prototype.getWalletUtxos = async function(walletId, stream, arg
};

/*
*BTCStateProvider.prototype.broadcastTransaction = async function(chain, tx) {
*BTCStateProvider.prototype.broadcastTransaction = async function(network, tx) {
* return this.get(chain).broadcastTransaction(tx);
*};
*/
2 changes: 1 addition & 1 deletion lib/providers/chain-state/btc/transforms.js
Original file line number Diff line number Diff line change
@@ -85,4 +85,4 @@ ListTransactionsStream.prototype._transform = function(transaction, enc, done) {
done();
};


module.exports = ListTransactionsStream;
4 changes: 2 additions & 2 deletions lib/providers/chain-state/index.js
Original file line number Diff line number Diff line change
@@ -56,8 +56,8 @@ ChainStateProvider.prototype.updateWallet = async function (chain, network, wal
return this.get(chain).updateWallet(walletId);
};

ChainStateProvider.prototype.getWalletTransactions = async function (chain, network, walletId) {
return this.get(chain).getWalletTransactions(walletId);
ChainStateProvider.prototype.getWalletTransactions = async function (chain, network, walletId, stream, args) {
return this.get(chain).getWalletTransactions(network, walletId, stream, args);
};

ChainStateProvider.prototype.getWalletBalance = async function (chain, network, walletId) {
35 changes: 12 additions & 23 deletions lib/routes/wallet.js
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ router.get('/:walletId/addresses', async function(req, res) {
}
ChainStateProvider.getWalletAddresses(chain, network, walletId, res);
} catch (err) {
console.error(err);
return res.status(500).send(err);
}
});
@@ -166,30 +167,18 @@ ListTransactionsStream.prototype._transform = function(transaction, enc, done) {
};

router.get('/:walletId/transactions', async (req, res) => {
let wallet = await Wallet.findOne({ _id: req.params.walletId }).exec();
if (!wallet) {
return res.status(404).send(new Error('Wallet not found'));
}
var query = {
wallets: wallet._id
};
if (req.query.startBlock) {
query.blockHeight = { $gte: parseInt(req.query.startBlock) };
}
if (req.query.endBlock) {
query.blockHeight = query.blockHeight || {};
query.blockHeight.$lte = parseInt(req.query.endBlock);
}
if (req.query.startDate) {
query.blockTimeNormalized = { $gte: new Date(req.query.startDate) };
}
if (req.query.endDate) {
query.blockTimeNormalized = query.blockTimeNormalized || {};
query.blockTimeNormalized.$lt = new Date(req.query.endDate);
let {walletId} = req.params;
let {chain, network} = req.query;
try {
let wallet = await Wallet.findOne({ _id: req.params.walletId }).exec();
if (!wallet) {
return res.status(404).send(new Error('Wallet not found'));
}
ChainStateProvider.getWalletTransactions(chain, network, walletId, res);
} catch(err) {
console.error(err);
return res.status(500).send(err);
}
var transactionStream = Transaction.getTransactions({query});
var listTransactionsStream = new ListTransactionsStream(wallet._id);
transactionStream.pipe(listTransactionsStream).pipe(res);
});

router.get('/:walletId/balance', async (req, res) => {