feat: extensions for SmartWeave global
This commit is contained in:
@@ -4,7 +4,9 @@ import {defaultCacheOptions, defaultWarpGwOptions, LoggerFactory, WarpFactory} f
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {JWKInterface} from 'arweave/node/lib/wallet';
|
||||
import {LmdbCache} from "warp-contracts-lmdb";
|
||||
import {WarpPlugin, WarpPluginType} from "../src/core/WarpPlugin";
|
||||
|
||||
const { NlpManager } = require('node-nlp');
|
||||
|
||||
async function main() {
|
||||
let wallet: JWKInterface = readJSON('./.secrets/33F0QHcb22W7LwWR1iRC8Az1ntZG09XQ03YWuw2ABqA.json');;
|
||||
@@ -17,18 +19,21 @@ async function main() {
|
||||
protocol: 'https'
|
||||
});
|
||||
|
||||
class NlpExtension implements WarpPlugin<any, void> {
|
||||
process(input: any): void {
|
||||
input.NlpManager = NlpManager;
|
||||
}
|
||||
|
||||
type(): WarpPluginType {
|
||||
return 'smartweave-extension';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
const warp = WarpFactory
|
||||
.forMainnet({...defaultCacheOptions, inMemory: false})
|
||||
.useStateCache(new LmdbCache({
|
||||
...defaultCacheOptions,
|
||||
dbLocation: `./cache/warp/state`
|
||||
}
|
||||
))
|
||||
.useContractCache(new LmdbCache({
|
||||
...defaultCacheOptions,
|
||||
dbLocation: `./cache/warp/contracts`
|
||||
}));
|
||||
.forMainnet({...defaultCacheOptions, inMemory: true})
|
||||
.use(new NlpExtension());
|
||||
/*const warp = WarpFactory
|
||||
.custom(arweave, {
|
||||
...defaultCacheOptions,
|
||||
@@ -47,11 +52,12 @@ async function main() {
|
||||
const initialState = fs.readFileSync(path.join(__dirname, 'data/js/token-pst.json'), 'utf8');
|
||||
|
||||
// case 1 - full deploy, js contract
|
||||
const {contractTxId} = await warp.createContract.deploy({
|
||||
/*const {contractTxId} = await warp.createContract.deploy({
|
||||
wallet,
|
||||
initState: initialState,
|
||||
src: jsContractSrc,
|
||||
});
|
||||
});*/
|
||||
|
||||
// case 2 - deploy from source, js contract
|
||||
/*const {contractTxId} = await warp.createContract.deployFromSourceTx({
|
||||
wallet,
|
||||
@@ -75,34 +81,31 @@ async function main() {
|
||||
srcTxId: "5wXT-A0iugP9pWEyw-iTbB0plZ_AbmvlNKyBfGS3AUY",
|
||||
});*/
|
||||
|
||||
const contract = warp.contract('hYZBzN5FsC7P90cmfNZ0eokOUyiIvPve6JUd-9EdPAQ')
|
||||
const contract = warp.contract<any>('QZfrcazIy1xhWhdztArMDSivrM23B0F4tAEFf6XJzt4')
|
||||
.setEvaluationOptions({
|
||||
})
|
||||
.connect(wallet);
|
||||
|
||||
/*await contract.writeInteraction({
|
||||
function: 'transfer',
|
||||
target: 'fffAfVHv6-qJmB9EISNLno6Tqcjp2-MS3R-m7d3hpOc',
|
||||
qty: 55555
|
||||
await contract.writeInteraction<any>({
|
||||
function: "train",
|
||||
});
|
||||
await contract.writeInteraction({
|
||||
function: 'transfer',
|
||||
target: 'fffAfVHv6-qJmB9EISNLno6Tqcjp2-MS3R-m7d3hpOc',
|
||||
qty: 55555
|
||||
|
||||
/*await contract.writeInteraction<any>({
|
||||
function: "storeBalance",
|
||||
target: "M-mpNeJbg9h7mZ-uHaNsa5jwFFRAq0PsTkNWXJ-ojwI",
|
||||
});
|
||||
await contract.writeInteraction({
|
||||
function: 'transfer',
|
||||
target: 'fffAfVHv6-qJmB9EISNLno6Tqcjp2-MS3R-m7d3hpOc',
|
||||
qty: 55555
|
||||
});
|
||||
await contract.writeInteraction({
|
||||
function: 'transfer',
|
||||
target: 'fffAfVHv6-qJmB9EISNLno6Tqcjp2-MS3R-m7d3hpOc',
|
||||
qty: 55555
|
||||
|
||||
await contract.writeInteraction<any>({
|
||||
function: "storeBalance",
|
||||
target: "M-mpNeJbg9h7mZ-uHaNsa5jwFFRAq0PsTkNWXJ-ojwI",
|
||||
});*/
|
||||
|
||||
const {cachedValue} = await contract.readState();
|
||||
|
||||
logger.info("Result", cachedValue.state);
|
||||
logger.info("errors", cachedValue.errorMessages);
|
||||
logger.info("Result");
|
||||
console.dir(cachedValue.state);
|
||||
|
||||
|
||||
} catch (e) {
|
||||
logger.error(e)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user