diff --git a/aspect/assembly/aspect/aspect.ts b/aspect/assembly/aspect/aspect.ts index 831ce19..f85c65e 100644 --- a/aspect/assembly/aspect/aspect.ts +++ b/aspect/assembly/aspect/aspect.ts @@ -90,14 +90,13 @@ export class Aspect implements IAspectTransaction, IAspectOperation, ITransactio "illegal session key scope, method isn't allowed. actual is " + method + ". detail: " + sys.utils.uint8ArrayToHex(ctx.tx.content.unwrap().input)); // 4. verify expire block height - // const response = sys.hostApi.runtimeContext.get("tx^context"); - // sys.require(response.result!.success, "get tx context fail"); - - // let tx = Protobuf.decode(response.data!.value, EthTransaction.decode) + const response = sys.hostApi.runtimeContext.get("block^header^0"); + var ethBlockHeader = Protobuf.decode(response.data!.value, EthBlockHeader.decode); + // const currentBlockHeight = ctx.tx.content.unwrap().blockNumber; const expireBlockHeight = sKeyObj.getExpireBlockHeight(); - const currentBlockHeight = expireBlockHeight - 1 ; + const currentBlockHeight = ethBlockHeader.number + 1; sys.require(currentBlockHeight <= expireBlockHeight, "session key has expired; " + expireBlockHeight.toString() + " < " + currentBlockHeight.toString()); diff --git a/aspect/tests/test_tx.cjs b/aspect/tests/test_tx.cjs index 109fd0a..02fb30e 100644 --- a/aspect/tests/test_tx.cjs +++ b/aspect/tests/test_tx.cjs @@ -185,15 +185,16 @@ async function f() { "// ******************************************\n\n"); let currentBlockHeight = await web3.eth.getBlockNumber(); - let expireBlockHeight = currentBlockHeight + 20; // ~10s - + console.log("currentBlockHeight :", currentBlockHeight); + let expireBlockHeight = currentBlockHeight + 10; // ~10s // let op = "0x0001" + sKey + sKeyContract + "0001" + contractCallMethod + expireBlockHeight; let op = "0x0001" + sKey + sKeyContract + "0001" + contractCallMethod - + web3.eth.abi.encodeParameter('uint256', expireBlockHeight).slice(48, 64); + + rmPrefix(web3.eth.abi.encodeParameter('uint256', expireBlockHeight)).slice(48, 64); + let sessionKeyRegData = aspect.operation(op).encodeABI(); console.log("op: ", op); console.log("calldata: ", sessionKeyRegData);