Skip to content

Commit

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

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

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

const requestsAndResponses = {
'["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'},
},
],
},
'{"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',
},
],
}

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

0 comments on commit b3ac102

Please sign in to comment.