feat: adding wasm-related info to ContractDefinition object
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
f54d421275
commit
5ae7fbba43
@@ -53,7 +53,7 @@
|
||||
"dependencies": {
|
||||
"@assemblyscript/loader": "^0.19.23",
|
||||
"@weavery/clarity": "^0.1.5",
|
||||
"arweave": "^1.10.23",
|
||||
"arweave": "1.10.23",
|
||||
"arweave-multihost": "^0.1.0",
|
||||
"axios": "^0.21.4",
|
||||
"bignumber.js": "^9.0.1",
|
||||
@@ -72,7 +72,7 @@
|
||||
"@types/node": "^16.7.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
||||
"@typescript-eslint/parser": "^4.29.2",
|
||||
"arlocal": "1.1.21",
|
||||
"arlocal": "1.1.22",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"cli-table": "0.3.11",
|
||||
"colors": "^1.4.0",
|
||||
|
||||
@@ -6,7 +6,8 @@ import { ContractType } from './modules/CreateContract';
|
||||
export type ContractDefinition<State> = {
|
||||
txId: string;
|
||||
srcTxId: string;
|
||||
src: Buffer;
|
||||
src: Buffer | string;
|
||||
srcWasmLang: string | null;
|
||||
initState: State;
|
||||
minFee: string;
|
||||
owner: string;
|
||||
|
||||
@@ -60,10 +60,23 @@ export class ContractDefinitionLoader implements DefinitionLoader {
|
||||
}
|
||||
const contractType: ContractType = srcContentType == 'application/javascript' ? 'js' : 'wasm';
|
||||
|
||||
const src = await this.arweaveWrapper.txData(contractSrcTxId);
|
||||
const src =
|
||||
contractType == 'js'
|
||||
? await this.arweaveWrapper.txDataString(contractSrcTxId)
|
||||
: await this.arweaveWrapper.txData(contractSrcTxId);
|
||||
|
||||
let srcWasmLang;
|
||||
if (contractType == 'wasm') {
|
||||
srcWasmLang = getTag(contractSrcTx, SmartWeaveTags.WASM_LANG);
|
||||
if (!srcWasmLang) {
|
||||
this.logger.warn('Wasm lang not set for wasm contract src', contractSrcTxId);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug('Contract src tx load', benchmark.elapsed());
|
||||
benchmark.reset();
|
||||
|
||||
const s = await this.evalInitialState(contractTx);
|
||||
this.logger.debug('init state', s);
|
||||
const initState = JSON.parse(await this.evalInitialState(contractTx));
|
||||
this.logger.debug('Parsing src and init state', benchmark.elapsed());
|
||||
|
||||
@@ -71,6 +84,7 @@ export class ContractDefinitionLoader implements DefinitionLoader {
|
||||
txId: contractTxId,
|
||||
srcTxId: contractSrcTxId,
|
||||
src,
|
||||
srcWasmLang,
|
||||
initState,
|
||||
minFee,
|
||||
owner,
|
||||
|
||||
@@ -89,13 +89,21 @@ export class ArweaveWrapper {
|
||||
}
|
||||
|
||||
async txData(id: string): Promise<Buffer> {
|
||||
// note: this is using arweave.net cache -
|
||||
// not very safe and clever, but fast...
|
||||
const response = await fetch(`${this.baseUrl}/${id}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Unable to load tx data ${id}`);
|
||||
}
|
||||
this.logger.warn(`Unable to load data from arweave.net/${id} endpoint, falling back to arweave.js`);
|
||||
// fallback to arweave-js as a last resort..
|
||||
const txData = (await this.arweave.transactions.getData(id, {
|
||||
decode: true
|
||||
})) as Uint8Array;
|
||||
return Buffer.from(txData);
|
||||
} else {
|
||||
const buffer = await response.arrayBuffer();
|
||||
return Buffer.from(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
async txDataString(id: string): Promise<string> {
|
||||
const buffer = await this.txData(id);
|
||||
|
||||
@@ -6,6 +6,7 @@ const { SmartWeaveWebFactory } = require('../lib/cjs/core/web/SmartWeaveWebFacto
|
||||
const {TsLogFactory} = require('../lib/cjs/logging/node/TsLogFactory');
|
||||
const fs = require('fs');
|
||||
const path =require('path');
|
||||
const {readContract} = require("smartweave");
|
||||
|
||||
const logger = LoggerFactory.INST.create('Contract');
|
||||
|
||||
@@ -14,15 +15,24 @@ LoggerFactory.INST.logLevel('info');
|
||||
|
||||
|
||||
async function main() {
|
||||
const arweave = Arweave.init({
|
||||
/*const arweave = Arweave.init({
|
||||
host: 'arweave.net', // Hostname or IP address for a Arweave host
|
||||
port: 443, // Port
|
||||
protocol: 'https', // Network protocol http or https
|
||||
timeout: 60000, // Network request timeouts in milliseconds
|
||||
logging: false // Enable network request logging
|
||||
});
|
||||
});*/
|
||||
|
||||
const contractTxId = '-8A6RexFkpfWwuyVO98wzSFZh0d6VJuI-buTJvlwOJQ';
|
||||
const arweave = Arweave.init({
|
||||
host: 'testnet.redstone.tools',
|
||||
protocol: 'https',
|
||||
port: 443,
|
||||
});
|
||||
const result = await readContract(arweave,"6hzHw8wwOuojRMpFOzlJCWJm2ls1Ch5L1U2gFLQI7NM")
|
||||
|
||||
console.log(result);
|
||||
|
||||
/*const contractTxId = '-8A6RexFkpfWwuyVO98wzSFZh0d6VJuI-buTJvlwOJQ';
|
||||
|
||||
//const interactionsLoader = new FromFileInteractionsLoader(path.join(__dirname, 'data', 'interactions.json'));
|
||||
|
||||
@@ -47,7 +57,7 @@ async function main() {
|
||||
//fs.writeFileSync(path.join(__dirname, 'data', 'validity.json'), JSON.stringify(validity));
|
||||
|
||||
//fs.writeFileSync(path.join(__dirname, 'data', 'validity_old.json'), JSON.stringify(result.validity));
|
||||
fs.writeFileSync(path.join(__dirname, 'data', 'state.json'), JSON.stringify(state));
|
||||
fs.writeFileSync(path.join(__dirname, 'data', 'state.json'), JSON.stringify(state));*/
|
||||
|
||||
// console.log('second read');
|
||||
// await lootContract.readState();
|
||||
@@ -21,7 +21,8 @@ LoggerFactory.INST.logLevel('info', 'Contract');
|
||||
LoggerFactory.INST.logLevel('debug', 'RedstoneGatewayInteractionsLoader');
|
||||
LoggerFactory.INST.logLevel('debug', 'RedstoneGatewayContractDefinitionLoader');
|
||||
LoggerFactory.INST.logLevel('error', 'DefaultStateEvaluator');
|
||||
LoggerFactory.INST.logLevel('error', 'DefaultStateEvaluator');
|
||||
LoggerFactory.INST.logLevel('debug', 'ArweaveWrapper');
|
||||
LoggerFactory.INST.logLevel('debug', 'ContractDefinitionLoader');
|
||||
|
||||
async function main() {
|
||||
printTestInfo();
|
||||
|
||||
32
yarn.lock
32
yarn.lock
@@ -1874,10 +1874,10 @@ argparse@^1.0.7:
|
||||
dependencies:
|
||||
sprintf-js "~1.0.2"
|
||||
|
||||
arlocal@1.1.21:
|
||||
version "1.1.21"
|
||||
resolved "https://registry.yarnpkg.com/arlocal/-/arlocal-1.1.21.tgz#92391facb5109c1014bd1c6c559cd5e737a1baa0"
|
||||
integrity sha512-cQqkDZikQ6e/NkAQIRwLt48qENr0DodiOmYr66y5wV1Di24SPzxMo9T+dBdgSzjuyCdMPv/73xVgPBtnG21GyA==
|
||||
arlocal@1.1.22:
|
||||
version "1.1.22"
|
||||
resolved "https://registry.yarnpkg.com/arlocal/-/arlocal-1.1.22.tgz#75ee7c4f8c7e54f8756f9df35439b764b5486404"
|
||||
integrity sha512-7p+Ic35ZagEOJRSnxpeJ6Gv6xsUVeBpn50ku1xA6m0eMM3ke+eBdoEVpaSsdaR8sAo840Vn/94Q5AHblw6Jt8Q==
|
||||
dependencies:
|
||||
"@koa/cors" "^3.1.0"
|
||||
apollo-server-koa "^3.6.2"
|
||||
@@ -1944,18 +1944,7 @@ arweave-stream-tx@^1.1.0:
|
||||
exponential-backoff "^3.1.0"
|
||||
stream-chunker "^1.2.8"
|
||||
|
||||
arweave@^1.10.13, arweave@^1.10.15, arweave@^1.10.16, arweave@^1.10.5:
|
||||
version "1.10.18"
|
||||
resolved "https://registry.npmjs.org/arweave/-/arweave-1.10.18.tgz"
|
||||
integrity sha512-i3pKBkLtU1Jl9RtJ9A6zgz8QqF5FZy7YA+qGQ9i2Zug171p29FTDZhN+KlRcVBg8sEgd1DKyecCCYJZ3K6Jdfg==
|
||||
dependencies:
|
||||
arconnect "^0.2.8"
|
||||
asn1.js "^5.4.1"
|
||||
axios "^0.22.0"
|
||||
base64-js "^1.3.1"
|
||||
bignumber.js "^9.0.1"
|
||||
|
||||
arweave@^1.10.18, arweave@^1.10.23:
|
||||
arweave@1.10.23, arweave@^1.10.18, arweave@^1.10.23:
|
||||
version "1.10.23"
|
||||
resolved "https://registry.yarnpkg.com/arweave/-/arweave-1.10.23.tgz#6edc056026d6c11ec47d817bb2c4f6d8fb8c65e5"
|
||||
integrity sha512-lAeCopS9iNGhmJkUovWqb7R+JEF83LP8f51rG+H98JPI9KQVRJYtM5NmMMU8auDtOzvBPTZ7me1pYn/CfS3VTg==
|
||||
@@ -1967,6 +1956,17 @@ arweave@^1.10.18, arweave@^1.10.23:
|
||||
bignumber.js "^9.0.1"
|
||||
util "^0.12.4"
|
||||
|
||||
arweave@^1.10.13, arweave@^1.10.15, arweave@^1.10.16, arweave@^1.10.5:
|
||||
version "1.10.18"
|
||||
resolved "https://registry.yarnpkg.com/arweave/-/arweave-1.10.18.tgz#3042edd1afa52b7c3caeacf88271758232c7b866"
|
||||
integrity sha512-i3pKBkLtU1Jl9RtJ9A6zgz8QqF5FZy7YA+qGQ9i2Zug171p29FTDZhN+KlRcVBg8sEgd1DKyecCCYJZ3K6Jdfg==
|
||||
dependencies:
|
||||
arconnect "^0.2.8"
|
||||
asn1.js "^5.4.1"
|
||||
axios "^0.22.0"
|
||||
base64-js "^1.3.1"
|
||||
bignumber.js "^9.0.1"
|
||||
|
||||
asn1.js@^5.4.1:
|
||||
version "5.4.1"
|
||||
resolved "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz"
|
||||
|
||||
Reference in New Issue
Block a user