-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: refactored getDataItem and prevalidateDataItem for every integration * fix: fixed labeling of nodejs version * feat: implemented parsed txs in cosmos runtime * fix: fixed bundle summary of cosmos integration * Update common/protocol/src/methods/timeouts/waitForAuthorization.ts Co-authored-by: John Letey <[email protected]> Co-authored-by: John Letey <[email protected]>
- Loading branch information
1 parent
d275567
commit fdd1ae0
Showing
11 changed files
with
111 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import axios from 'axios'; | ||
import { createHash } from 'crypto'; | ||
import { sleep } from '@kyvejs/protocol'; | ||
|
||
export async function fetchBlock( | ||
endpoint: string, | ||
height: number, | ||
headers: any | ||
): Promise<any> { | ||
const value = await call<any>( | ||
`${endpoint}/cosmos/base/tendermint/v1beta1/blocks/${height}`, | ||
headers | ||
); | ||
|
||
const parsed_txs = await fetchTransactions( | ||
endpoint, | ||
value.block.data.txs.map(parseEncodedTx), | ||
headers | ||
); | ||
|
||
return { | ||
...value, | ||
__kyve: { | ||
block: { | ||
data: { | ||
parsed_txs, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
async function fetchTransactions( | ||
endpoint: string, | ||
hashes: string[], | ||
headers: any | ||
): Promise<any[]> { | ||
const txs: any[] = []; | ||
|
||
for (const hash of hashes) { | ||
try { | ||
const tx = await call<any>( | ||
`${endpoint}/cosmos/tx/v1beta1/txs/${hash}`, | ||
headers | ||
); | ||
|
||
txs.push(tx.tx_response); | ||
} catch { | ||
txs.push(null); | ||
} finally { | ||
await sleep(500); | ||
} | ||
} | ||
|
||
return txs; | ||
} | ||
|
||
async function call<T>(endpoint: string, headers: any): Promise<T> { | ||
const { data } = await axios.get<T>(endpoint, { | ||
headers, | ||
}); | ||
|
||
return data; | ||
} | ||
|
||
function parseEncodedTx(tx: string): string { | ||
const txBytes = new Uint8Array( | ||
createHash('sha256').update(Buffer.from(tx, 'base64')).digest() | ||
); | ||
|
||
return Buffer.from(txBytes.slice(0, 32)).toString('hex').toUpperCase(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters