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": {
|
"dependencies": {
|
||||||
"@assemblyscript/loader": "^0.19.23",
|
"@assemblyscript/loader": "^0.19.23",
|
||||||
"@weavery/clarity": "^0.1.5",
|
"@weavery/clarity": "^0.1.5",
|
||||||
"arweave": "^1.10.23",
|
"arweave": "1.10.23",
|
||||||
"arweave-multihost": "^0.1.0",
|
"arweave-multihost": "^0.1.0",
|
||||||
"axios": "^0.21.4",
|
"axios": "^0.21.4",
|
||||||
"bignumber.js": "^9.0.1",
|
"bignumber.js": "^9.0.1",
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
"@types/node": "^16.7.1",
|
"@types/node": "^16.7.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
||||||
"@typescript-eslint/parser": "^4.29.2",
|
"@typescript-eslint/parser": "^4.29.2",
|
||||||
"arlocal": "1.1.21",
|
"arlocal": "1.1.22",
|
||||||
"cheerio": "^1.0.0-rc.10",
|
"cheerio": "^1.0.0-rc.10",
|
||||||
"cli-table": "0.3.11",
|
"cli-table": "0.3.11",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import { ContractType } from './modules/CreateContract';
|
|||||||
export type ContractDefinition<State> = {
|
export type ContractDefinition<State> = {
|
||||||
txId: string;
|
txId: string;
|
||||||
srcTxId: string;
|
srcTxId: string;
|
||||||
src: Buffer;
|
src: Buffer | string;
|
||||||
|
srcWasmLang: string | null;
|
||||||
initState: State;
|
initState: State;
|
||||||
minFee: string;
|
minFee: string;
|
||||||
owner: string;
|
owner: string;
|
||||||
|
|||||||
@@ -60,10 +60,23 @@ export class ContractDefinitionLoader implements DefinitionLoader {
|
|||||||
}
|
}
|
||||||
const contractType: ContractType = srcContentType == 'application/javascript' ? 'js' : 'wasm';
|
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());
|
this.logger.debug('Contract src tx load', benchmark.elapsed());
|
||||||
benchmark.reset();
|
benchmark.reset();
|
||||||
|
const s = await this.evalInitialState(contractTx);
|
||||||
|
this.logger.debug('init state', s);
|
||||||
const initState = JSON.parse(await this.evalInitialState(contractTx));
|
const initState = JSON.parse(await this.evalInitialState(contractTx));
|
||||||
this.logger.debug('Parsing src and init state', benchmark.elapsed());
|
this.logger.debug('Parsing src and init state', benchmark.elapsed());
|
||||||
|
|
||||||
@@ -71,6 +84,7 @@ export class ContractDefinitionLoader implements DefinitionLoader {
|
|||||||
txId: contractTxId,
|
txId: contractTxId,
|
||||||
srcTxId: contractSrcTxId,
|
srcTxId: contractSrcTxId,
|
||||||
src,
|
src,
|
||||||
|
srcWasmLang,
|
||||||
initState,
|
initState,
|
||||||
minFee,
|
minFee,
|
||||||
owner,
|
owner,
|
||||||
|
|||||||
@@ -89,12 +89,20 @@ export class ArweaveWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async txData(id: string): Promise<Buffer> {
|
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}`);
|
const response = await fetch(`${this.baseUrl}/${id}`);
|
||||||
if (!response.ok) {
|
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);
|
||||||
}
|
}
|
||||||
const buffer = await response.arrayBuffer();
|
|
||||||
return Buffer.from(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async txDataString(id: string): Promise<string> {
|
async txDataString(id: string): Promise<string> {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const { SmartWeaveWebFactory } = require('../lib/cjs/core/web/SmartWeaveWebFacto
|
|||||||
const {TsLogFactory} = require('../lib/cjs/logging/node/TsLogFactory');
|
const {TsLogFactory} = require('../lib/cjs/logging/node/TsLogFactory');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path =require('path');
|
const path =require('path');
|
||||||
|
const {readContract} = require("smartweave");
|
||||||
|
|
||||||
const logger = LoggerFactory.INST.create('Contract');
|
const logger = LoggerFactory.INST.create('Contract');
|
||||||
|
|
||||||
@@ -14,15 +15,24 @@ LoggerFactory.INST.logLevel('info');
|
|||||||
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const arweave = Arweave.init({
|
/*const arweave = Arweave.init({
|
||||||
host: 'arweave.net', // Hostname or IP address for a Arweave host
|
host: 'arweave.net', // Hostname or IP address for a Arweave host
|
||||||
port: 443, // Port
|
port: 443, // Port
|
||||||
protocol: 'https', // Network protocol http or https
|
protocol: 'https', // Network protocol http or https
|
||||||
timeout: 60000, // Network request timeouts in milliseconds
|
timeout: 60000, // Network request timeouts in milliseconds
|
||||||
logging: false // Enable network request logging
|
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'));
|
//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.json'), JSON.stringify(validity));
|
||||||
|
|
||||||
//fs.writeFileSync(path.join(__dirname, 'data', 'validity_old.json'), JSON.stringify(result.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');
|
// console.log('second read');
|
||||||
// await lootContract.readState();
|
// await lootContract.readState();
|
||||||
@@ -21,7 +21,8 @@ LoggerFactory.INST.logLevel('info', 'Contract');
|
|||||||
LoggerFactory.INST.logLevel('debug', 'RedstoneGatewayInteractionsLoader');
|
LoggerFactory.INST.logLevel('debug', 'RedstoneGatewayInteractionsLoader');
|
||||||
LoggerFactory.INST.logLevel('debug', 'RedstoneGatewayContractDefinitionLoader');
|
LoggerFactory.INST.logLevel('debug', 'RedstoneGatewayContractDefinitionLoader');
|
||||||
LoggerFactory.INST.logLevel('error', 'DefaultStateEvaluator');
|
LoggerFactory.INST.logLevel('error', 'DefaultStateEvaluator');
|
||||||
LoggerFactory.INST.logLevel('error', 'DefaultStateEvaluator');
|
LoggerFactory.INST.logLevel('debug', 'ArweaveWrapper');
|
||||||
|
LoggerFactory.INST.logLevel('debug', 'ContractDefinitionLoader');
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
printTestInfo();
|
printTestInfo();
|
||||||
|
|||||||
32
yarn.lock
32
yarn.lock
@@ -1874,10 +1874,10 @@ argparse@^1.0.7:
|
|||||||
dependencies:
|
dependencies:
|
||||||
sprintf-js "~1.0.2"
|
sprintf-js "~1.0.2"
|
||||||
|
|
||||||
arlocal@1.1.21:
|
arlocal@1.1.22:
|
||||||
version "1.1.21"
|
version "1.1.22"
|
||||||
resolved "https://registry.yarnpkg.com/arlocal/-/arlocal-1.1.21.tgz#92391facb5109c1014bd1c6c559cd5e737a1baa0"
|
resolved "https://registry.yarnpkg.com/arlocal/-/arlocal-1.1.22.tgz#75ee7c4f8c7e54f8756f9df35439b764b5486404"
|
||||||
integrity sha512-cQqkDZikQ6e/NkAQIRwLt48qENr0DodiOmYr66y5wV1Di24SPzxMo9T+dBdgSzjuyCdMPv/73xVgPBtnG21GyA==
|
integrity sha512-7p+Ic35ZagEOJRSnxpeJ6Gv6xsUVeBpn50ku1xA6m0eMM3ke+eBdoEVpaSsdaR8sAo840Vn/94Q5AHblw6Jt8Q==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@koa/cors" "^3.1.0"
|
"@koa/cors" "^3.1.0"
|
||||||
apollo-server-koa "^3.6.2"
|
apollo-server-koa "^3.6.2"
|
||||||
@@ -1944,18 +1944,7 @@ arweave-stream-tx@^1.1.0:
|
|||||||
exponential-backoff "^3.1.0"
|
exponential-backoff "^3.1.0"
|
||||||
stream-chunker "^1.2.8"
|
stream-chunker "^1.2.8"
|
||||||
|
|
||||||
arweave@^1.10.13, arweave@^1.10.15, arweave@^1.10.16, arweave@^1.10.5:
|
arweave@1.10.23, arweave@^1.10.18, arweave@^1.10.23:
|
||||||
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:
|
|
||||||
version "1.10.23"
|
version "1.10.23"
|
||||||
resolved "https://registry.yarnpkg.com/arweave/-/arweave-1.10.23.tgz#6edc056026d6c11ec47d817bb2c4f6d8fb8c65e5"
|
resolved "https://registry.yarnpkg.com/arweave/-/arweave-1.10.23.tgz#6edc056026d6c11ec47d817bb2c4f6d8fb8c65e5"
|
||||||
integrity sha512-lAeCopS9iNGhmJkUovWqb7R+JEF83LP8f51rG+H98JPI9KQVRJYtM5NmMMU8auDtOzvBPTZ7me1pYn/CfS3VTg==
|
integrity sha512-lAeCopS9iNGhmJkUovWqb7R+JEF83LP8f51rG+H98JPI9KQVRJYtM5NmMMU8auDtOzvBPTZ7me1pYn/CfS3VTg==
|
||||||
@@ -1967,6 +1956,17 @@ arweave@^1.10.18, arweave@^1.10.23:
|
|||||||
bignumber.js "^9.0.1"
|
bignumber.js "^9.0.1"
|
||||||
util "^0.12.4"
|
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:
|
asn1.js@^5.4.1:
|
||||||
version "5.4.1"
|
version "5.4.1"
|
||||||
resolved "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz"
|
resolved "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz"
|
||||||
|
|||||||
Reference in New Issue
Block a user