fix: sdk should not cache on requested block height if interactions come from redstone-sequencer
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
c9924a7443
commit
7a7a9be1f8
73
tools/bundle.ts
Normal file
73
tools/bundle.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
/* eslint-disable */
|
||||
import Arweave from 'arweave';
|
||||
import {
|
||||
LoggerFactory,
|
||||
MemCache,
|
||||
RedstoneGatewayContractDefinitionLoader,
|
||||
RedstoneGatewayInteractionsLoader,
|
||||
SmartWeaveNodeFactory
|
||||
} from '../src';
|
||||
import { readJSON } from '../../redstone-smartweave-examples/src/_utils';
|
||||
import { TsLogFactory } from '../src/logging/node/TsLogFactory';
|
||||
|
||||
const logger = LoggerFactory.INST.create('Contract');
|
||||
|
||||
LoggerFactory.use(new TsLogFactory());
|
||||
LoggerFactory.INST.logLevel('error');
|
||||
LoggerFactory.INST.logLevel('info', 'Contract');
|
||||
LoggerFactory.INST.logLevel('debug', 'RedstoneGatewayInteractionsLoader');
|
||||
LoggerFactory.INST.logLevel('error', 'DefaultStateEvaluator');
|
||||
LoggerFactory.INST.logLevel('error', 'LexicographicalInteractionsSorter');
|
||||
|
||||
async function main() {
|
||||
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 smartweave = SmartWeaveNodeFactory.memCachedBased(arweave)
|
||||
.setInteractionsLoader(
|
||||
new RedstoneGatewayInteractionsLoader('http://localhost:5666', { notCorrupted: true })
|
||||
)
|
||||
.setDefinitionLoader(
|
||||
new RedstoneGatewayContractDefinitionLoader('https://gateway.redstone.finance', arweave, new MemCache())
|
||||
)
|
||||
.build();
|
||||
|
||||
const jwk = readJSON('../redstone-node/.secrets/redstone-jwk.json');
|
||||
// connecting to a given contract
|
||||
const token = smartweave
|
||||
.contract("OrO8n453N6bx921wtsEs-0OCImBLCItNU5oSbFKlFuU")
|
||||
.setEvaluationOptions({
|
||||
sequencerAddress: "http://localhost:5666/"
|
||||
})
|
||||
// connecting wallet to a contract. It is required before performing any "writeInteraction"
|
||||
// calling "writeInteraction" without connecting to a wallet first will cause a runtime error.
|
||||
.connect(jwk);
|
||||
|
||||
const result1 = await token.readState();
|
||||
|
||||
logger.info("Amount of computed interactions before 'bundleInteraction':", Object.keys(result1.validity).length);
|
||||
|
||||
const result = await token.bundleInteraction<any>({
|
||||
function: "transfer",
|
||||
data: {
|
||||
target: "fake-from-bundle",
|
||||
qty: 18599333,
|
||||
},
|
||||
});
|
||||
|
||||
logger.info("Result from the sequencer", result.id);
|
||||
|
||||
// the new transaction is instantly available - ie. during the state read operation
|
||||
const result2 = await token.readState();
|
||||
|
||||
logger.info("Amount of computed interactions after 'bundleInteraction':", Object.keys(result2.validity).length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
main().catch((e) => console.error(e));
|
||||
Reference in New Issue
Block a user