-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #822 from flytam/task7
task7: flytam
- Loading branch information
Showing
20 changed files
with
10,778 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
privateKey.txt |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"targets": { | ||
"debug": { | ||
"outFile": "build/debug.wasm", | ||
"textFile": "build/debug.wat", | ||
"sourceMap": true, | ||
"debug": true | ||
}, | ||
"release": { | ||
"outFile": "build/release.wasm", | ||
"textFile": "build/release.wat", | ||
"sourceMap": true, | ||
"optimizeLevel": 3, | ||
"shrinkLevel": 0, | ||
"converge": false, | ||
"noAssert": false | ||
} | ||
}, | ||
"options": { | ||
"bindings": "esm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
allocate, | ||
entryPoint, | ||
execute, | ||
IPreContractCallJP, | ||
PreContractCallInput, | ||
sys, | ||
uint8ArrayToHex, | ||
UintData, | ||
} from "@artela/aspect-libs"; | ||
import {Protobuf} from "as-proto/assembly"; | ||
|
||
/** | ||
*/ | ||
class Aspect implements IPreContractCallJP { | ||
/** | ||
* | ||
* @param input | ||
*/ | ||
preContractCall(input: PreContractCallInput): void { | ||
// read the throttle config from the properties and decode | ||
const interval = sys.aspect.property.get<u64>("interval") | ||
const limit = sys.aspect.property.get<u64>('limit') | ||
|
||
// get the contract address, from address and build the storage prefix | ||
const contractAddress = uint8ArrayToHex(input.call!.to); | ||
const from = uint8ArrayToHex(input.call!.from); | ||
const storagePrefix = `${contractAddress}:${from}:` | ||
|
||
// load the current block timestamp | ||
const blockTimeBytes = sys.hostApi.runtimeContext.get('block.header.timestamp') | ||
const blockTime = Protobuf.decode<UintData>(blockTimeBytes, UintData.decode).data | ||
|
||
// load last execution timestamp | ||
const lastExecState = sys.aspect.mutableState.get<u64>(storagePrefix + 'lastExecAt') | ||
const lastExec = lastExecState.unwrap() | ||
|
||
// check if the throttle interval has passed, revert if not | ||
if (lastExec > 0 && (blockTime - lastExec) < interval) { | ||
sys.revert('throttled') | ||
} | ||
|
||
// check if the throttle limit has been reached, revert if so | ||
const execTimesState = sys.aspect.mutableState.get<u64>(storagePrefix + 'execTimes') | ||
let execTimes = execTimesState.unwrap() | ||
if (limit && execTimes >= limit) { | ||
sys.revert('execution time exceeded') | ||
} | ||
|
||
// update the throttle state | ||
execTimesState.set(execTimes + 1) | ||
lastExecState.set(blockTime) | ||
} | ||
|
||
/** | ||
* isOwner is the governance account implemented by the Aspect, when any of the governance operation | ||
* (including upgrade, config, destroy) is made, isOwner method will be invoked to check | ||
* against the initiator's account to make sure it has the permission. | ||
* | ||
* @param sender address of the transaction | ||
* @return true if check success, false if check fail | ||
*/ | ||
isOwner(sender: Uint8Array): bool { | ||
return false; | ||
} | ||
} | ||
|
||
// 2.register aspect Instance | ||
const aspect = new Aspect() | ||
entryPoint.setAspect(aspect) | ||
|
||
// 3.must export it | ||
export { execute, allocate } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "assemblyscript/std/assembly.json", | ||
"include": [ | ||
"./**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract Counter { | ||
uint256 _count; | ||
address private deployer; | ||
|
||
constructor() { | ||
deployer = msg.sender; | ||
_count = 0; | ||
} | ||
|
||
function isOwner(address user) external view returns (bool result) { | ||
if (user == deployer) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
function increment() public { | ||
_count = _count + 1; | ||
} | ||
|
||
function count() public view returns (uint256) { | ||
return _count; | ||
} | ||
} |
Oops, something went wrong.