本Aspect可以为智能合约启用黑名单功能。用户可以将账户添加到黑名单或从黑名单中删除。如果黑名单中的地址尝试访问智能合约,该Aspect将阻止合约的执行。
.
├── README.md
├── asconfig.json
├── aspect <-- 你的切面代码存放在这里
│ └── index.ts
├── contracts <-- 在这里放置你的智能合约
├── scripts <-- 实用脚本,包括部署、绑定等。
│ ├── aspect-deploy.cjs
│ ├── bind.cjs
│ ├── contract-call.cjs
│ └── contract-deploy.cjs
...
创建一个新的钱包地址
$ npm run account:create
address: 0x6B70B03B608a19Bf1817848A4C8FFF844f0Be0fB
此脚本将在项目目录中创建一个名为 privateKey.txt 的私钥文件。你也可以输入自己的私钥(Hex格式)。然后从Artela Discord faucet获取测试代币。
$ npm run contract:build
$ npm run contract:deploy -- --bytecode ./build/contract/Counter.bin --abi ./build/contract/Counter.abi
> contract:deploy
> node scripts/contract-deploy.cjs --bytecode ./build/contract/Counter.bin --abi ./build/contract/Counter.abi
from address: 0xdc863fd839e6a55E804Ae45ffd7A7606aDD7F1e2
(node:82367) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
deploy contract tx hash: 0xdc4274875ba014f9009185ec9eb20e4565edbcf3a73be270869d7ae16c4e9cb4
{
blockHash: '0x23df4a37f4565a85a72d591bc7c4356e0880f3c5e2880a88ce3e6276682b3b64',
blockNumber: 10587877,
contractAddress: '0x01D3b3aa301dE819184Dd5b4ec07a20FaBf26d02',
cumulativeGasUsed: 3500000,
from: '0xdc863fd839e6a55e804ae45ffd7a7606add7f1e2',
gasUsed: 7000001,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
to: null,
transactionHash: '0xdc4274875ba014f9009185ec9eb20e4565edbcf3a73be270869d7ae16c4e9cb4',
transactionIndex: 0,
type: '0x0'
}
contract address: 0x01D3b3aa301dE819184Dd5b4ec07a20FaBf26d02
--contractAccount 0xdc863fd839e6a55E804Ae45ffd7A7606aDD7F1e2 --contractAddress 0x01D3b3aa301dE819184Dd5b4ec07a20FaBf26d02
请记住已部署合约的地址,稍后用于绑定。
$ npm run aspect:build
编译成功后,执行部署脚本。
$ npm run aspect:deploy -- --properties '[{"key":"owner","value":"0xdc863fd839e6a55e804ae45ffd7a7606add7f1e2"}]' --joinPoints PreContractCall
from address: 0xdc863fd839e6a55E804Ae45ffd7A7606aDD7F1e2
sending signed transaction...
{
blockHash: '0x2fce10b2a16c6c06b7a17302c328c24be1d0cbe0d570f9407a4db8af3e13f812',
blockNumber: 10587869,
contractAddress: null,
cumulativeGasUsed: 21000,
from: '0xdc863fd839e6a55e804ae45ffd7a7606add7f1e2',
gasUsed: 9000001,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
to: '0x0000000000000000000000000000000000a27e14',
transactionHash: '0xcaebf0c142ff67e034728afda3c7bd625088ec09bf48b157c62ddf5328270905',
transactionIndex: 1,
type: '0x0',
aspectAddress: '0x8f80C7a29eC332F878fA13d2396ED6f7189ef875'
}
ret: {
blockHash: '0x2fce10b2a16c6c06b7a17302c328c24be1d0cbe0d570f9407a4db8af3e13f812',
blockNumber: 10587869,
contractAddress: null,
cumulativeGasUsed: 21000,
from: '0xdc863fd839e6a55e804ae45ffd7a7606add7f1e2',
gasUsed: 9000001,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
to: '0x0000000000000000000000000000000000a27e14',
transactionHash: '0xcaebf0c142ff67e034728afda3c7bd625088ec09bf48b157c62ddf5328270905',
transactionIndex: 1,
type: '0x0',
aspectAddress: '0x8f80C7a29eC332F878fA13d2396ED6f7189ef875'
}
== deploy aspectID == 0x8f80C7a29eC332F878fA13d2396ED6f7189ef875
参数:
- owner: 你的账户地址,确保添加/删除黑名单操作成功。
- joinPoints: 必须指定,用于与Aspect绑定。
请记录Aspect ID,用于后续绑定操作
使用已部署的合约地址Aspect ID运行 bind.cjs
脚本。
$ npm run contract:bind -- --contract 0x01D3b3aa301dE819184Dd5b4ec07a20FaBf26d02 --aspectId 0x8f80C7a29eC332F878fA13d2396ED6f7189ef875 --abi ./build/contract/Counter.abi
sending signed transaction...
{
blockHash: '0x1c210bb3c50d2574a49626a514a607b34ed0c13660e330d35109e246fa60bada',
blockNumber: 10587894,
contractAddress: null,
cumulativeGasUsed: 0,
from: '0xdc863fd839e6a55e804ae45ffd7a7606add7f1e2',
gasUsed: 9000001,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
to: '0x0000000000000000000000000000000000a27e14',
transactionHash: '0x1622ea134aca41a66f9089965416e5b102eb2f78dea85d4543f75833b858917a',
transactionIndex: 0,
type: '0x0'
}
== aspect bind success ==
随后,我们可以执行查询脚本查询绑定情况
$ node scripts/get-bound-aspect.cjs --contract <CONTRAT_ADDRESS>
bound aspects : 0x8f80C7a29eC332F878fA13d2396ED6f7189ef875,1,1
--callData
中 0x 后的第一位数字表示操作类型:0 代表删除,1 代表添加。
$ npm run operation:send -- --aspectId 0x8f80C7a29eC332F878fA13d2396ED6f7189ef875 --callData 0x0dc863fd839e6a55e804ae45ffd7a7606add7f1e2
> operation:send
> node scripts/operation.cjs --isCall false --aspectId 0x8f80C7a29eC332F878fA13d2396ED6f7189ef875 --callData 0x0dc863fd839e6a55e804ae45ffd7a7606add7f1e2
(node:99615) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
{
blockHash: '0x0761a3d549a448dc4fdecce4c86887c32779d5c2412d830f8f7e170aec4d1468',
blockNumber: 10588795,
contractAddress: null,
cumulativeGasUsed: 326612,
from: '0xdc863fd839e6a55e804ae45ffd7a7606add7f1e2',
gasUsed: 900000,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
to: '0x0000000000000000000000000000000000a27e14',
transactionHash: '0x0e24d901e51c58186446399da1e2dca68e16e802c350ac3ab917d28dc54fc299',
transactionIndex: 3,
type: '0x0'
}
使用以下命令调用合约。如果地址未列入黑名单,交易将通过;否则,交易将失败。
$ npm run contract:send -- --contract 0x01D3b3aa301dE819184Dd5b4ec07a20FaBf26d02 --abi ./build/contract/Counter.abi --method increase
> contract:send
> node scripts/contract-send.cjs --contract 0x01D3b3aa301dE819184Dd5b4ec07a20FaBf26d02 --abi ./build/contract/Counter.abi --method increase
(node:169) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
from address: 0xdc863fd839e6a55E804Ae45ffd7A7606aDD7F1e2
call contract tx hash: 0xd22f1ecd48e06f6b64de32241a7e3f71ee2f6c2b12b2d58f985828cc4fe0ee7f
{
blockHash: '0x348d63de6c3c64214b31c57d2c64bb7facd3b606f381a6c28dca44d259918ae7',
blockNumber: 10588809,
contractAddress: null,
cumulativeGasUsed: 2000000,
from: '0xdc863fd839e6a55e804ae45ffd7a7606add7f1e2',
gasUsed: 4000001,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
to: '0x01d3b3aa301de819184dd5b4ec07a20fabf26d02',
transactionHash: '0xd22f1ecd48e06f6b64de32241a7e3f71ee2f6c2b12b2d58f985828cc4fe0ee7f',
transactionIndex: 0,
type: '0x0'
}