feat: skip unsafe foreign contract calls
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export function handle(state, action) {
|
||||
export async function handle(state, action) {
|
||||
const balances = state.balances;
|
||||
const canEvolve = state.canEvolve;
|
||||
const input = action.input;
|
||||
@@ -91,5 +91,31 @@ export function handle(state, action) {
|
||||
return {state};
|
||||
}
|
||||
|
||||
if (input.function === 'readForeign') {
|
||||
if (state.foreignCallsCounter === undefined) {
|
||||
state.foreignCallsCounter = 0;
|
||||
}
|
||||
const result = await SmartWeave.contracts.readContractState(input.contractTxId, true);
|
||||
state.foreignCallsCounter++; // this should not happen for unsafe contracts when skipUnsafe is set to true
|
||||
return {state};
|
||||
}
|
||||
|
||||
if (input.function === 'writeForeign') {
|
||||
console.log('writeForeign');
|
||||
const result = await SmartWeave.contracts.write(input.contractTxId, {
|
||||
function: "callFromForeign"
|
||||
});
|
||||
return {state};
|
||||
}
|
||||
|
||||
if (input.function === 'callFromForeign') {
|
||||
console.log('callFromForeign');
|
||||
if (state.foreignCallsCounter === undefined) {
|
||||
state.foreignCallsCounter = 0;
|
||||
}
|
||||
state.foreignCallsCounter++;
|
||||
return {state};
|
||||
}
|
||||
|
||||
throw new ContractError(`No function supplied or function not recognised: "${input.function}"`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user