Skip to content

Commit

Permalink
use old utxo endpoint again
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 committed Jan 25, 2019
1 parent 621f0b5 commit 214fbee
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 71 deletions.
25 changes: 9 additions & 16 deletions app/frontend/wallet/blockchain-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,22 @@ const blockchainExplorer = (ADALITE_CONFIG, walletState) => {
const nonemptyAddresses = await selectNonemptyAddresses(addresses)
const chunks = range(0, Math.ceil(nonemptyAddresses.length / 10))

const url = 'https://iohk-mainnet.yoroiwallet.com/api/txs/utxoForAddresses'
const url = `${ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL}/api/bulk/addresses/utxo`
const response = (await Promise.all(
chunks.map(async (index) => {
return await request(
url,
'POST',
JSON.stringify({
addresses: nonemptyAddresses.slice(index, 10),
}),
{
'Accept': 'application/json',
'Content-Type': 'application/json',
}
)
return (await request(url, 'POST', JSON.stringify(nonemptyAddresses.slice(index, 10)), {
'Accept': 'application/json',
'Content-Type': 'application/json',
})).Right
})
)).reduce((acc, cur) => acc.concat(cur), [])

return response.map((elem) => {
return {
txHash: elem.tx_hash,
address: elem.receiver,
coins: parseInt(elem.amount, 10),
outputIndex: elem.tx_index,
txHash: elem.cuId,
address: elem.cuAddress,
coins: parseInt(elem.cuCoins.getCoin, 10),
outputIndex: elem.cuOutIndex,
}
})
}
Expand Down
114 changes: 59 additions & 55 deletions app/tests/src/common/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -1581,68 +1581,72 @@ const mock = (ADALITE_CONFIG) => {
fetchMock.config.overwriteRoutes = true

const requestsAndResponses = {
'{"addresses":["DdzFFzCqrhsjeiN7xW9DpwoPh13BMwDctP9RrufwAMa1dRmFaR9puCyckq4mXkjeZk1VsEJqxkb89z636SsGQ4x54boVoX3DRW3QC9g5","DdzFFzCqrhtCrR5oxyvhmRCfwFJ4tKXo7xocEXGoEMruhp23eddcuZVegJiiyJtuY5NDgG9eoe7CHVDRcszfKTKcHAxccvDVs1xwK7Gz"]}': [
{
tx_hash: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
tx_index: 0,
receiver:
'DdzFFzCqrhsjeiN7xW9DpwoPh13BMwDctP9RrufwAMa1dRmFaR9puCyckq4mXkjeZk1VsEJqxkb89z636SsGQ4x54boVoX3DRW3QC9g5',
amount: '100000',
},
{
tx_hash: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
tx_index: 1,
receiver:
'DdzFFzCqrhtCrR5oxyvhmRCfwFJ4tKXo7xocEXGoEMruhp23eddcuZVegJiiyJtuY5NDgG9eoe7CHVDRcszfKTKcHAxccvDVs1xwK7Gz',
amount: '2867795',
},
],
'{"addresses":["DdzFFzCqrhsvrNGcR93DW8cmrPVVbP6vFxcL1i92WzvqcHrp1K1of4DQ8t8cr3oQgsMbbY1eXKWhrcpfnTohNqrr6zPdLeE3AYBtxxZZ","DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC"]}': [
{
tx_hash: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
tx_index: 0,
receiver:
'DdzFFzCqrhsvrNGcR93DW8cmrPVVbP6vFxcL1i92WzvqcHrp1K1of4DQ8t8cr3oQgsMbbY1eXKWhrcpfnTohNqrr6zPdLeE3AYBtxxZZ',
amount: '500000',
},
{
tx_hash: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
tx_index: 1,
receiver:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
amount: '1000000',
},
{
tx_hash: 'aa22f977c2671836647d347ebe23822269ce21cd22f231e1279018b569dcd48c',
tx_index: 0,
receiver:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
amount: '6000',
},
{
tx_hash: '73131c773879e7e634022f8e0175399b7e7814c42684377cf6f8c7a1adb23112',
tx_index: 1,
receiver:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
amount: '125',
},
{
tx_hash: '1ce7a1e2606271a7f085262fb7c509c98d60912a943c9be3871ac3ace48ae6d6',
tx_index: 1,
receiver:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
amount: '5000',
},
],
'["DdzFFzCqrhsjeiN7xW9DpwoPh13BMwDctP9RrufwAMa1dRmFaR9puCyckq4mXkjeZk1VsEJqxkb89z636SsGQ4x54boVoX3DRW3QC9g5","DdzFFzCqrhtCrR5oxyvhmRCfwFJ4tKXo7xocEXGoEMruhp23eddcuZVegJiiyJtuY5NDgG9eoe7CHVDRcszfKTKcHAxccvDVs1xwK7Gz"]': {
Right: [
{
cuId: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
cuOutIndex: 0,
cuAddress:
'DdzFFzCqrhsjeiN7xW9DpwoPh13BMwDctP9RrufwAMa1dRmFaR9puCyckq4mXkjeZk1VsEJqxkb89z636SsGQ4x54boVoX3DRW3QC9g5',
cuCoins: {getCoin: '100000'},
},
{
cuId: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
cuOutIndex: 1,
cuAddress:
'DdzFFzCqrhtCrR5oxyvhmRCfwFJ4tKXo7xocEXGoEMruhp23eddcuZVegJiiyJtuY5NDgG9eoe7CHVDRcszfKTKcHAxccvDVs1xwK7Gz',
cuCoins: {getCoin: '2867795'},
},
],
},
'["DdzFFzCqrhsvrNGcR93DW8cmrPVVbP6vFxcL1i92WzvqcHrp1K1of4DQ8t8cr3oQgsMbbY1eXKWhrcpfnTohNqrr6zPdLeE3AYBtxxZZ","DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC"]': {
Right: [
{
cuId: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
cuOutIndex: 0,
cuAddress:
'DdzFFzCqrhsvrNGcR93DW8cmrPVVbP6vFxcL1i92WzvqcHrp1K1of4DQ8t8cr3oQgsMbbY1eXKWhrcpfnTohNqrr6zPdLeE3AYBtxxZZ',
cuCoins: {getCoin: '500000'},
},
{
cuId: '6ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765',
cuOutIndex: 1,
cuAddress:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
cuCoins: {getCoin: '1000000'},
},
{
cuId: 'aa22f977c2671836647d347ebe23822269ce21cd22f231e1279018b569dcd48c',
cuOutIndex: 0,
cuAddress:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
cuCoins: {getCoin: '6000'},
},
{
cuId: '73131c773879e7e634022f8e0175399b7e7814c42684377cf6f8c7a1adb23112',
cuOutIndex: 1,
cuAddress:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
cuCoins: {getCoin: '125'},
},
{
cuId: '1ce7a1e2606271a7f085262fb7c509c98d60912a943c9be3871ac3ace48ae6d6',
cuOutIndex: 1,
cuAddress:
'DdzFFzCqrhtA8C86FGbYkcnHuu8uNmjZ4M6pDKKYXAwZRYr1Q8mXHmUFhgjcTCkuSDnx8xA7tu75727wAc6Ki5nM2PDFK3JXfdYfbvHC',
cuCoins: {getCoin: '5000'},
},
],
},
}

// eslint-disable-next-line guard-for-in
for (const request in requestsAndResponses) {
fetchMock.post({
name: `https://iohk-mainnet.yoroiwallet.com/api/txs/utxoForAddresses${request}`,
name: `${ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL}/api/bulk/addresses/utxo${request}`,
matcher: (url, opts) => {
return (
url === 'https://iohk-mainnet.yoroiwallet.com/api/txs/utxoForAddresses' &&
url === `${ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL}/api/bulk/addresses/utxo` &&
opts &&
opts.body === request
)
Expand Down

0 comments on commit 214fbee

Please sign in to comment.