Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/vsc-eco/vsc-node into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vaultec81 committed Apr 24, 2024
2 parents 704fc26 + 348576b commit 2faa292
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
36 changes: 32 additions & 4 deletions src/services/new/contractEngineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,43 @@ class VmContext {

console.log(tx)


const blockHeader = await this.engine.self.chainBridge.blockHeaders.findOne(tx.anchored_id ? {
id: tx.anchored_id
} : {
slot_height: {$lte: tx.anchored_height}
}, tx.anchored_id ? {} : {
sort: {
slot_height: -1
}
})
const requiredAuths = tx.required_auths.map(e => typeof e === 'string' ? e : e.value).map(e => {
if(tx.src === 'hive') {
//Format should be human readable
return `hive:${e}`
} else {
//i.e did:key:123etcetc
return e
}
})

const callOutput = await this.vm.call({
contract_id,
action: tx.data.action,
payload: JSON.stringify(tx.data.payload),
env: {

} as any
'anchor.id': blockHeader.id,
'anchor.height': tx.anchored_height,
'anchor.block': tx.anchored_block || `hive:${tx.id}`,
'anchor.timestamp': blockHeader.ts.getTime(),


'msg.sender': requiredAuths[0],
//Retain the type info as well.
//TODO: properly parse and provide authority type to contract
//Such as ACTIVE vs POSTING auth
'msg.required_auths': requiredAuths,
'tx.origin': requiredAuths[0],
}
})

return callOutput
Expand Down Expand Up @@ -257,7 +285,7 @@ export class ContractEngineV2 {
//Such as ACTIVE vs POSTING auth
'msg.required_auths': tx.required_auths,
'tx.origin': requiredAuths[0],
} as any
}
})


Expand Down
20 changes: 14 additions & 6 deletions src/services/new/vm/vm-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,17 @@ class VmRunner {

let modules = {}
for (let [contract_id, code] of Object.entries<string>(this.modules)) {
const binaryData = await ipfs.dag.get(IPFS.CID.parse(code))
const cid = IPFS.CID.parse(code)
const binaryData = await (async () => {
switch (cid.code) {
case 0x71:
return (await ipfs.dag.get(cid)).value
case 0x55:
return await ipfs.block.get(cid)
}
})()
try {
modules[contract_id] = await WebAssembly.compile(binaryData.value)
modules[contract_id] = await WebAssembly.compile(binaryData)
} catch (e) {
console.error(`invalid contract code ${contract_id}`, e)
}
Expand Down Expand Up @@ -508,7 +516,7 @@ class VmRunner {
const block_height = args.block_height
const memory = new WebAssembly.Memory({
initial: 10,
maximum: 128,
maximum: 12800,
})

let IOGas = 0
Expand Down Expand Up @@ -708,7 +716,7 @@ class VmRunner {

return insta.exports.__newString(val)
},
'db.delObject': async (keyPtr) => {
'db.delObject': (keyPtr) => {
const key = (insta as any).exports.__getString(keyPtr)
wasmRunner.tmpState.set(key, null)
},
Expand All @@ -730,7 +738,7 @@ class VmRunner {

return insta.exports.__newString(resultData)
},
'system.getEnv': async (envPtr) => {
'system.getEnv': (envPtr) => {
const envArg = insta.exports.__getString(envPtr)

return insta.exports.__newString(
Expand Down Expand Up @@ -790,7 +798,7 @@ class VmRunner {
return {
type: 'execute-stop',
ret: null,
error: ex.toString(),
error: ex.toString() + ' ' + ex.stack,
errorType: ContractErrorType.RUNTIME_UNKNOWN,
logs,
// reqId: message.reqId,
Expand Down
10 changes: 5 additions & 5 deletions src/services/new/witness/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ export class WitnessServiceV2 {
results[contract_id].push({
id: tx.id,
result: {
ret: contractCallResult.ret,
error: contractCallResult.error,
errorType: contractCallResult.errorType,
logs: contractCallResult.logs,
IOGas: contractCallResult.IOGas
ret: contractCallResult.ret ?? null,
error: contractCallResult.error ?? null,
errorType: contractCallResult.errorType ?? null,
logs: contractCallResult.logs ?? null,
IOGas: contractCallResult.IOGas ?? null,
}
})
}
Expand Down

0 comments on commit 2faa292

Please sign in to comment.