Implement data source and crypto host APIs (#104)

* Implement data source host APIs

* Implement crypto host API
This commit is contained in:
2021-12-30 17:57:34 +05:30
committed by GitHub
parent 8b913af93f
commit 6a2c99a0bb
7 changed files with 106 additions and 10 deletions
@@ -1,4 +1,4 @@
import { Address, log, BigInt, BigDecimal, ByteArray, dataSource, ethereum, Bytes } from '@graphprotocol/graph-ts';
import { Address, log, BigInt, BigDecimal, ByteArray, dataSource, ethereum, Bytes, crypto } from '@graphprotocol/graph-ts';
import {
Example1,
@@ -14,6 +14,9 @@ export function handleTest (event: Test): void {
log.debug('event.block.hash: {}', [event.block.hash.toHexString()]);
log.debug('event.block.stateRoot: {}', [event.block.stateRoot.toHexString()]);
log.debug('dataSource.network: {}', [dataSource.network()]);
log.debug('dataSource.context: {}', [dataSource.context().entries.length.toString()]);
// Entities can be loaded from the store using a string ID; this ID
// needs to be unique across all entities of the same type
let author = Author.load(event.transaction.from.toHex());
@@ -504,3 +507,12 @@ export function testEthereumDecode (encoded: string): string[] {
decodedBool.toString()
];
}
export function testCrypto (hexString: string): string {
const byteArray = ByteArray.fromHexString(hexString);
const keccak256 = crypto.keccak256(byteArray);
const keccak256String = keccak256.toHex();
log.debug('keccak256 string: {}', [keccak256String]);
return keccak256String;
}