feat: use redstone gateway by default

This commit is contained in:
ppe
2022-05-10 13:08:24 +02:00
committed by just_ppe
parent 9125b5a109
commit 15a14e183d
21 changed files with 109 additions and 109 deletions

View File

@@ -32,7 +32,7 @@ describe('Testing the SmartWeave client', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -46,7 +46,7 @@ describe('Testing the SmartWeave client', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -44,7 +44,7 @@ describe('Testing the SmartWeave client', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.fileCached(arweave, cacheDir);
smartweave = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build();
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);
@@ -108,11 +108,11 @@ describe('Testing the SmartWeave client', () => {
});
it('should properly read state with a fresh client', async () => {
const contract2 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir)
const contract2 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build()
.contract<ExampleContractState>(contract.txId())
.connect(wallet);
const contract2VM = SmartWeaveNodeFactory.fileCached(arweave, cacheDir)
const contract2VM = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build()
.contract<ExampleContractState>(contract.txId())
.connect(wallet);
expect((await contract2.readState()).state.counter).toEqual(559);
@@ -127,10 +127,10 @@ describe('Testing the SmartWeave client', () => {
});
it('should properly read state with another fresh client', async () => {
const contract3 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir)
const contract3 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build()
.contract<ExampleContractState>(contract.txId())
.connect(wallet);
const contract3VM = SmartWeaveNodeFactory.fileCached(arweave, cacheDir)
const contract3VM = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build()
.contract<ExampleContractState>(contract.txId())
.setEvaluationOptions({
useVM2: true
@@ -153,10 +153,10 @@ describe('Testing the SmartWeave client', () => {
await contract.writeInteraction({ function: 'add' });
await mineBlock(arweave);
const contract4 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir)
const contract4 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build()
.contract<ExampleContractState>(contract.txId())
.connect(wallet);
const contract4VM = SmartWeaveNodeFactory.fileCached(arweave, cacheDir)
const contract4VM = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build()
.contract<ExampleContractState>(contract.txId())
.setEvaluationOptions({
useVM2: true

View File

@@ -35,7 +35,7 @@ describe('Testing the SmartWeave client', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -12,6 +12,10 @@ interface ExampleContractState {
counter: number;
}
async function getSmartWeave(arweave: Arweave, knexConfig: Knex<any, unknown[]>) {
return (await SmartWeaveNodeFactory.knexCachedBased(arweave, knexConfig)).useArweaveGateway().build();
}
/**
* This integration test should verify whether the basic functions of the SmartWeave client
* work properly when Knex cache is being used.
@@ -64,7 +68,7 @@ describe('Testing the SmartWeave client', () => {
LoggerFactory.INST.logLevel('error');
smartweave = await SmartWeaveNodeFactory.knexCached(arweave, knexConfig);
smartweave = await getSmartWeave(arweave, knexConfig);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);
@@ -158,20 +162,20 @@ describe('Testing the SmartWeave client', () => {
});
it('should properly read state with a fresh client', async () => {
const contract_1_2 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_1_2 = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_1.txId())
.connect(wallet);
const contract_1_2VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_1_2VM = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_1.txId())
.setEvaluationOptions({ useVM2: true })
.connect(wallet);
expect((await contract_1_2.readState()).state.counter).toEqual(559);
expect((await contract_1_2VM.readState()).state.counter).toEqual(559);
const contract_2_2 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_2_2 = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_2.txId())
.connect(wallet);
const contract_2_2VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_2_2VM = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_2.txId())
.setEvaluationOptions({ useVM2: true })
.connect(wallet);
@@ -192,17 +196,17 @@ describe('Testing the SmartWeave client', () => {
});
it('should properly read state with another fresh client', async () => {
const contract_1_3 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_1_3 = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_1.txId())
.connect(wallet);
const contract_1_3VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_1_3VM = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_1.txId())
.setEvaluationOptions({ useVM2: true })
.connect(wallet);
const contract_2_3 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_2_3 = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_2.txId())
.connect(wallet);
const contract_2_3VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_2_3VM = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_2.txId())
.setEvaluationOptions({ useVM2: true })
.connect(wallet);
@@ -233,17 +237,17 @@ describe('Testing the SmartWeave client', () => {
await contract_2.writeInteraction({ function: 'add' });
await mineBlock(arweave);
const contract_1_4 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_1_4 = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_1.txId())
.connect(wallet);
const contract_1_4VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_1_4VM = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_1.txId())
.setEvaluationOptions({ useVM2: true })
.connect(wallet);
const contract_2_4 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_2_4 = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_2.txId())
.connect(wallet);
const contract_2_4VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig))
const contract_2_4VM = (await getSmartWeave(arweave, knexConfig))
.contract<ExampleContractState>(contract_2.txId())
.setEvaluationOptions({ useVM2: true })
.connect(wallet);
@@ -259,7 +263,7 @@ describe('Testing the SmartWeave client', () => {
});
it('should allow to manually flush cache', async () => {
const smartweave = await SmartWeaveNodeFactory.knexCached(arweave, knexConfig2);
const smartweave = await getSmartWeave(arweave, knexConfig2);
const contract = smartweave
.contract<ExampleContractState>(contract_1.txId())

View File

@@ -39,7 +39,7 @@ describe('Testing the Profit Sharing Token', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.fileCached(arweave, cacheDir);
smartweave = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build();
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);
@@ -123,7 +123,7 @@ describe('Testing the Profit Sharing Token', () => {
});
it('should load updated source code', async () => {
const smartweave2 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir);
const smartweave2 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build();
// connecting to the PST contract
pst = smartweave2.pst(contractTxId);

View File

@@ -42,7 +42,7 @@ describe('Testing the Profit Sharing Token', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -32,7 +32,7 @@ describe('Testing the SmartWeave client', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -73,7 +73,7 @@ describe('Testing internal writes', () => {
});
async function deployContracts() {
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);
@@ -177,11 +177,11 @@ describe('Testing internal writes', () => {
});
it('should properly evaluate state with a new client', async () => {
const contractA2 = SmartWeaveNodeFactory.memCached(arweave)
const contractA2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractATxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
const contractB2 = SmartWeaveNodeFactory.memCached(arweave)
const contractB2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractBTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
@@ -217,11 +217,11 @@ describe('Testing internal writes', () => {
});
it('should properly evaluate state with a new client', async () => {
const contractA2 = SmartWeaveNodeFactory.memCached(arweave)
const contractA2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractATxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
const contractB2 = SmartWeaveNodeFactory.memCached(arweave)
const contractB2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractBTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
@@ -280,11 +280,11 @@ describe('Testing internal writes', () => {
});
xit('should properly evaluate state with a new client', async () => {
const contractA2 = SmartWeaveNodeFactory.memCached(arweave)
const contractA2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractATxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
const contractB2 = SmartWeaveNodeFactory.memCached(arweave)
const contractB2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractBTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
@@ -339,11 +339,11 @@ describe('Testing internal writes', () => {
});
it('should properly evaluate state with a new client', async () => {
const contractA2 = SmartWeaveNodeFactory.memCached(arweave)
const contractA2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractATxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
const contractB2 = SmartWeaveNodeFactory.memCached(arweave)
const contractB2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractBTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);

View File

@@ -75,7 +75,7 @@ describe('Testing internal writes', () => {
});
async function deployContracts() {
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);
@@ -262,12 +262,12 @@ describe('Testing internal writes', () => {
});
it('should properly evaluate state again with a new client', async () => {
const calleeContract2 = SmartWeaveNodeFactory.memCached(arweave)
const calleeContract2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<ExampleContractState>(calleeTxId)
.setEvaluationOptions({
internalWrites: true
});
const calleeContract2VM = SmartWeaveNodeFactory.memCached(arweave)
const calleeContract2VM = SmartWeaveNodeFactory.forTesting(arweave)
.contract<ExampleContractState>(calleeTxId)
.setEvaluationOptions({
internalWrites: true,

View File

@@ -87,7 +87,7 @@ describe('Testing internal writes', () => {
});
async function deployContracts() {
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -89,7 +89,7 @@ describe('Testing internal writes', () => {
});
async function deployContracts() {
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);
@@ -208,11 +208,11 @@ describe('Testing internal writes', () => {
});
it('should properly evaluate state with a new client', async () => {
const contractB2 = SmartWeaveNodeFactory.memCached(arweave)
const contractB2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractBTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
const contractC2 = SmartWeaveNodeFactory.memCached(arweave)
const contractC2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractCTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);

View File

@@ -83,7 +83,7 @@ describe('Testing internal writes', () => {
});
async function deployContracts() {
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);
@@ -340,11 +340,11 @@ describe('Testing internal writes', () => {
});
it('should properly evaluate state with a new client', async () => {
const contractB2 = SmartWeaveNodeFactory.memCached(arweave)
const contractB2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractBTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);
const contractC2 = SmartWeaveNodeFactory.memCached(arweave)
const contractC2 = SmartWeaveNodeFactory.forTesting(arweave)
.contract<any>(contractCTxId)
.setEvaluationOptions({ internalWrites: true })
.connect(wallet);

View File

@@ -57,7 +57,7 @@ describe('Testing internal writes', () => {
});
async function deployContracts() {
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -39,7 +39,7 @@ describe('Testing the SmartWeave client for AssemblyScript WASM contract', () =>
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -45,7 +45,7 @@ describe('Testing the Go WASM Profit Sharing Token', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -51,7 +51,7 @@ describe('Testing the Rust WASM Profit Sharing Token', () => {
LoggerFactory.INST.logLevel('error');
smartweave = SmartWeaveNodeFactory.memCached(arweave);
smartweave = SmartWeaveNodeFactory.forTesting(arweave);
wallet = await arweave.wallets.generate();
await addFunds(arweave, wallet);

View File

@@ -111,7 +111,10 @@ describe.each(chunkedGw)('gateways compare.suite %#', (contracts: string[]) => {
const resultString = stringify(result.state).trim();
console.log('readState Arweave Gateway', contractTxId);
const result2 = await SmartWeaveNodeFactory.memCached(arweave, 1).contract(contractTxId).readState(blockHeight);
const result2 = await SmartWeaveNodeFactory.memCachedBased(arweave, 1)
.useArweaveGateway()
.build()
.contract(contractTxId).readState(blockHeight);
const result2String = stringify(result2.state).trim();
expect(result2String).toEqual(resultString);
},

View File

@@ -1,7 +1,8 @@
import Arweave from 'arweave';
import {
ArweaveGatewayInteractionsLoader,
CacheableContractInteractionsLoader,
ConfirmationStatus,
ConfirmationStatus, ContractDefinitionLoader,
DebuggableExecutorFactory,
DefinitionLoader,
ExecutorFactory,
@@ -84,6 +85,21 @@ export class SmartWeaveBuilder {
return this;
}
public useArweaveGateway(): SmartWeaveBuilder {
this._definitionLoader = new ContractDefinitionLoader(this._arweave, new MemCache());
this._interactionsLoader = new CacheableContractInteractionsLoader(
new ArweaveGatewayInteractionsLoader(this._arweave),
new MemBlockHeightSwCache(1)
);
this._useRedstoneGwInfo = false;
return this;
}
public useRedStoneGwInfo(): SmartWeaveBuilder {
this._useRedstoneGwInfo = true;
return this;
}
build(): SmartWeave {
return new SmartWeave(
this._arweave,

View File

@@ -1,10 +1,13 @@
import Arweave from 'arweave';
import {
ArweaveGatewayInteractionsLoader,
CacheableStateEvaluator,
CacheableStateEvaluator, ConfirmationStatus,
ContractDefinitionLoader,
HandlerExecutorFactory,
LexicographicalInteractionsSorter,
R_GW_URL,
RedstoneGatewayContractDefinitionLoader,
RedstoneGatewayInteractionsLoader,
SmartWeave,
SmartWeaveBuilder,
SmartWeaveWebFactory
@@ -18,6 +21,13 @@ import { KnexStateCache } from '../../cache/impl/KnexStateCache';
* A {@link SmartWeave} factory that can be safely used only in Node.js env.
*/
export class SmartWeaveNodeFactory extends SmartWeaveWebFactory {
/**
* Returns a fully configured, memcached {@link SmartWeave} that is suitable for tests with ArLocal
*/
static forTesting(arweave: Arweave): SmartWeave {
return this.memCachedBased(arweave).useArweaveGateway().build();
}
/**
* Returns a fully configured {@link SmartWeave} that is using file-based cache for {@link StateEvaluator} layer
* and mem cache for the rest.
@@ -41,12 +51,11 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory {
static fileCachedBased(
arweave: Arweave,
cacheBasePath?: string,
maxStoredInMemoryBlockHeights = 10
maxStoredInMemoryBlockHeights = 10,
confirmationStatus: ConfirmationStatus = { notCorrupted: true }
): SmartWeaveBuilder {
const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache());
const gatewayInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave);
const interactionsLoader = new RedstoneGatewayInteractionsLoader(R_GW_URL, confirmationStatus);
const definitionLoader = new RedstoneGatewayContractDefinitionLoader(R_GW_URL, arweave, new MemCache());
const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache());
const stateEvaluator = new CacheableStateEvaluator(
@@ -59,7 +68,8 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory {
return SmartWeave.builder(arweave)
.setDefinitionLoader(definitionLoader)
.setCacheableInteractionsLoader(gatewayInteractionsLoader)
.setInteractionsLoader(interactionsLoader)
.useRedStoneGwInfo()
.setInteractionsSorter(interactionsSorter)
.setExecutorFactory(executorFactory)
.setStateEvaluator(stateEvaluator);
@@ -78,11 +88,11 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory {
static async knexCachedBased(
arweave: Arweave,
dbConnection: Knex,
maxStoredInMemoryBlockHeights = 10
maxStoredInMemoryBlockHeights = 10,
confirmationStatus: ConfirmationStatus = { notCorrupted: true }
): Promise<SmartWeaveBuilder> {
const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache());
const gatewayInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave);
const interactionsLoader = new RedstoneGatewayInteractionsLoader(R_GW_URL, confirmationStatus);
const definitionLoader = new RedstoneGatewayContractDefinitionLoader(R_GW_URL, arweave, new MemCache());
const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache());
@@ -96,7 +106,8 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory {
return SmartWeave.builder(arweave)
.setDefinitionLoader(definitionLoader)
.setCacheableInteractionsLoader(gatewayInteractionsLoader)
.setInteractionsLoader(interactionsLoader)
.useRedStoneGwInfo()
.setInteractionsSorter(interactionsSorter)
.setExecutorFactory(executorFactory)
.setStateEvaluator(stateEvaluator);

View File

@@ -3,9 +3,13 @@ import { CacheableContractInteractionsLoader, CacheableExecutorFactory, Evolve }
import {
ArweaveGatewayInteractionsLoader,
CacheableStateEvaluator,
ConfirmationStatus,
ContractDefinitionLoader,
HandlerExecutorFactory,
LexicographicalInteractionsSorter,
R_GW_URL,
RedstoneGatewayContractDefinitionLoader,
RedstoneGatewayInteractionsLoader,
SmartWeave,
SmartWeaveBuilder,
StateCache
@@ -18,44 +22,6 @@ import { MemBlockHeightSwCache, MemCache, RemoteBlockHeightCache } from '@smartw
* SmartWeave instances created by this factory can be safely used in a web environment.
*/
export class SmartWeaveWebFactory {
/**
* Returns a fully configured {@link SmartWeave} that is using remote cache for all layers.
* See {@link RemoteBlockHeightCache} for details.
*/
static remoteCached(arweave: Arweave, cacheBaseURL: string): SmartWeave {
return this.remoteCacheBased(arweave, cacheBaseURL).build();
}
/**
* Returns a preconfigured, remoteCached {@link SmartWeaveBuilder}, that allows for customization of the SmartWeave instance.
* Use {@link SmartWeaveBuilder.build()} to finish the configuration.
*/
static remoteCacheBased(arweave: Arweave, cacheBaseURL: string): SmartWeaveBuilder {
const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache());
const interactionsLoader = new CacheableContractInteractionsLoader(
new ArweaveGatewayInteractionsLoader(arweave),
new RemoteBlockHeightCache('INTERACTIONS', cacheBaseURL)
);
const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache());
const stateEvaluator = new CacheableStateEvaluator(
arweave,
new RemoteBlockHeightCache<StateCache<unknown>>('STATE', cacheBaseURL),
[new Evolve(definitionLoader, executorFactory)]
);
const interactionsSorter = new LexicographicalInteractionsSorter(arweave);
return SmartWeave.builder(arweave)
.setDefinitionLoader(definitionLoader)
.setInteractionsLoader(interactionsLoader)
.setInteractionsSorter(interactionsSorter)
.setExecutorFactory(executorFactory)
.setStateEvaluator(stateEvaluator);
}
/**
* Returns a fully configured {@link SmartWeave} that is using mem cache for all layers.
*/
@@ -70,17 +36,16 @@ export class SmartWeaveWebFactory {
static memCachedBased(
arweave: Arweave,
maxStoredBlockHeights = 10,
stateCache?: MemBlockHeightSwCache<StateCache<unknown>>
confirmationStatus: ConfirmationStatus = { notCorrupted: true }
): SmartWeaveBuilder {
const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache());
const interactionsLoader = new ArweaveGatewayInteractionsLoader(arweave);
const interactionsLoader = new RedstoneGatewayInteractionsLoader(R_GW_URL, confirmationStatus);
const definitionLoader = new RedstoneGatewayContractDefinitionLoader(R_GW_URL, arweave, new MemCache());
const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache());
const stateEvaluator = new CacheableStateEvaluator(
arweave,
stateCache ? stateCache : new MemBlockHeightSwCache<StateCache<unknown>>(maxStoredBlockHeights),
new MemBlockHeightSwCache<StateCache<unknown>>(maxStoredBlockHeights),
[new Evolve(definitionLoader, executorFactory)]
);
@@ -88,7 +53,8 @@ export class SmartWeaveWebFactory {
return SmartWeave.builder(arweave)
.setDefinitionLoader(definitionLoader)
.setCacheableInteractionsLoader(interactionsLoader)
.setInteractionsLoader(interactionsLoader)
.useRedStoneGwInfo()
.setInteractionsSorter(interactionsSorter)
.setExecutorFactory(executorFactory)
.setStateEvaluator(stateEvaluator);