feat: skip unsafe foreign contract calls

This commit is contained in:
ppe
2022-11-28 10:10:00 +01:00
committed by just_ppe
parent 247ece88be
commit 4ab7790cda
23 changed files with 38093 additions and 91 deletions

View File

@@ -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}"`);
}