@rootzero/contracts 1.10.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -1
- package/Core.sol +1 -0
- package/Endpoints.sol +2 -3
- package/Events.sol +2 -5
- package/README.md +38 -36
- package/Utils.sol +2 -1
- package/blocks/Cursors.sol +39 -75
- package/blocks/Keys.sol +18 -4
- package/blocks/Schema.sol +53 -47
- package/commands/Base.sol +43 -13
- package/commands/Burn.sol +3 -6
- package/commands/Credit.sol +4 -6
- package/commands/Debit.sol +10 -11
- package/commands/Deposit.sol +19 -23
- package/commands/Payout.sol +6 -10
- package/commands/Provision.sol +19 -23
- package/commands/Recover.sol +7 -9
- package/commands/Relay.sol +10 -11
- package/commands/Withdraw.sol +3 -6
- package/commands/admin/AllowAssets.sol +7 -10
- package/commands/admin/Allowance.sol +7 -10
- package/commands/admin/Appoint.sol +7 -10
- package/commands/admin/Authorize.sol +10 -19
- package/commands/admin/Base.sol +1 -2
- package/commands/admin/DenyAssets.sol +7 -10
- package/commands/admin/Dismiss.sol +7 -10
- package/commands/admin/Execute.sol +7 -10
- package/commands/admin/Label.sol +8 -11
- package/commands/admin/Schemas.sol +31 -0
- package/commands/admin/Unauthorize.sol +10 -19
- package/core/Endpoint.sol +160 -0
- package/core/Host.sol +1 -1
- package/docs/Schema.md +124 -86
- package/events/Endpoint.sol +19 -0
- package/events/Schema.sol +23 -0
- package/guards/Base.sol +17 -8
- package/guards/Revoke.sol +4 -6
- package/package.json +1 -1
- package/ports/AllowAssets.sol +6 -9
- package/ports/Allowance.sol +6 -9
- package/ports/Base.sol +21 -8
- package/ports/Credit.sol +6 -9
- package/ports/Debit.sol +6 -9
- package/ports/DenyAssets.sol +6 -9
- package/ports/Dispatch.sol +6 -9
- package/ports/Pipe.sol +4 -7
- package/ports/Redeem.sol +4 -7
- package/ports/Settle.sol +6 -9
- package/queries/Assets.sol +9 -12
- package/queries/Balances.sol +7 -9
- package/queries/Base.sol +19 -11
- package/utils/Selectors.sol +49 -0
- package/commands/admin/Destroy.sol +0 -43
- package/commands/admin/Init.sol +0 -43
- package/events/Admin.sol +0 -32
- package/events/Command.sol +0 -32
- package/events/Guard.sol +0 -18
- package/events/Port.sol +0 -22
- package/events/Query.sol +0 -20
- package/queries/Positions.sol +0 -54
package/commands/Relay.sol
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import {CommandBase, CommandContext, Keys} from "./Base.sol";
|
|
5
|
+
import {Lane} from "../core/Endpoint.sol";
|
|
5
6
|
import {Payable} from "../core/Payable.sol";
|
|
6
|
-
import {Cursors, Cur
|
|
7
|
+
import {Cursors, Cur} from "../Cursors.sol";
|
|
7
8
|
import {Budget} from "../utils/Value.sol";
|
|
8
9
|
|
|
9
10
|
using Cursors for Cur;
|
|
@@ -25,25 +26,23 @@ abstract contract RoutePayableHook {
|
|
|
25
26
|
/// the same state from being duplicated across multiple relays.
|
|
26
27
|
/// Produces no output state.
|
|
27
28
|
abstract contract RelayPayable is CommandBase, Payable, RoutePayableHook {
|
|
28
|
-
|
|
29
|
+
bytes32 private immutable descriptor;
|
|
29
30
|
|
|
30
31
|
constructor() {
|
|
31
|
-
|
|
32
|
-
emit Labeled(relayPayableId, bytes32(0), "relayPayable");
|
|
32
|
+
(, descriptor) = command("relayPayable", Keys.Any, Keys.Relay, Keys.Empty, 0, true, false);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/// @notice Relay one RELAY request block with the command account and current state.
|
|
36
|
-
/// @param c Command context; `c.
|
|
37
|
-
/// @return
|
|
38
|
-
function relayPayable(CommandContext calldata c) external payable onlyCommand returns (bytes memory
|
|
39
|
-
Cur memory
|
|
40
|
-
|
|
36
|
+
/// @param c Command context; `c.input` must contain exactly one RELAY block.
|
|
37
|
+
/// @return Empty output state.
|
|
38
|
+
function relayPayable(CommandContext calldata c) external payable onlyCommand returns (bytes memory) {
|
|
39
|
+
(Cur memory input, , ) = openLane(c.input, descriptor, Lane.Input, 1);
|
|
40
|
+
(uint portal, uint resources, bytes memory context) = input.relayToContext(c.account, c.state);
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
Budget memory budget = openValue();
|
|
43
43
|
route(portal, resources, context, budget);
|
|
44
44
|
|
|
45
45
|
closeValue(c.account, budget);
|
|
46
|
-
request.complete();
|
|
47
46
|
return "";
|
|
48
47
|
}
|
|
49
48
|
}
|
package/commands/Withdraw.sol
CHANGED
|
@@ -19,11 +19,10 @@ abstract contract WithdrawHook {
|
|
|
19
19
|
/// Use `withdraw` for assets being sent outside the protocol (e.g. ERC-20 transfers, ETH sends).
|
|
20
20
|
/// For internal balance credits, use `creditAccount` instead.
|
|
21
21
|
abstract contract Withdraw is CommandBase, WithdrawHook {
|
|
22
|
-
|
|
22
|
+
bytes32 private immutable descriptor;
|
|
23
23
|
|
|
24
24
|
constructor() {
|
|
25
|
-
|
|
26
|
-
emit Labeled(withdrawId, bytes32(0), "withdraw");
|
|
25
|
+
(, descriptor) = command("withdraw", Keys.Balance, Keys.Empty, Keys.Empty, 0, false, false);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
/// @notice Withdraw each BALANCE block from the command state to the command account.
|
|
@@ -32,14 +31,12 @@ abstract contract Withdraw is CommandBase, WithdrawHook {
|
|
|
32
31
|
function withdraw(
|
|
33
32
|
CommandContext calldata c
|
|
34
33
|
) external onlyCommand returns (bytes memory) {
|
|
35
|
-
(Cur memory state, ) =
|
|
34
|
+
(Cur memory state, ) = openState(c.state, descriptor);
|
|
36
35
|
|
|
37
36
|
while (state.i < state.len) {
|
|
38
37
|
(bytes32 asset, uint amount) = state.unpackBalance();
|
|
39
38
|
withdraw(c.account, asset, amount);
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
state.complete();
|
|
43
40
|
return "";
|
|
44
41
|
}
|
|
45
42
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import { AdminBase, CommandContext, Keys } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur
|
|
5
|
+
import { Cursors, Cur } from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
abstract contract AllowAssetsHook {
|
|
@@ -16,27 +16,24 @@ abstract contract AllowAssetsHook {
|
|
|
16
16
|
/// @notice Admin command that permits a list of assets via a virtual hook.
|
|
17
17
|
/// Each ASSET block in the request calls `allowAsset`. Only callable by the admin account.
|
|
18
18
|
abstract contract AllowAssets is AdminBase, AllowAssetsHook {
|
|
19
|
-
|
|
19
|
+
bytes32 private immutable descriptor;
|
|
20
20
|
|
|
21
21
|
constructor() {
|
|
22
|
-
|
|
23
|
-
emit Labeled(allowAssetsId, bytes32(0), "allowAssets");
|
|
22
|
+
(, descriptor) = command("allowAssets", Keys.Empty, Keys.Asset, Keys.Empty, 0, false, true);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
/// @notice Allow each ASSET block in the admin request.
|
|
27
|
-
/// @param c Admin command context; `c.
|
|
26
|
+
/// @param c Admin command context; `c.input` must contain ASSET blocks.
|
|
28
27
|
/// @return Empty output state.
|
|
29
28
|
function allowAssets(
|
|
30
29
|
CommandContext calldata c
|
|
31
30
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
32
|
-
(Cur memory
|
|
31
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
33
32
|
|
|
34
|
-
while (
|
|
35
|
-
bytes32 asset =
|
|
33
|
+
while (input.i < input.len) {
|
|
34
|
+
bytes32 asset = input.unpackAsset();
|
|
36
35
|
allowAsset(asset);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
request.complete();
|
|
40
37
|
return "";
|
|
41
38
|
}
|
|
42
39
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import {AdminBase, CommandContext, Keys} from "./Base.sol";
|
|
5
|
-
import {Cursors, Cur
|
|
5
|
+
import {Cursors, Cur} from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
abstract contract AllowanceHook {
|
|
@@ -20,25 +20,22 @@ abstract contract AllowanceHook {
|
|
|
20
20
|
/// @notice Admin command that applies cross-host allowance entries via a virtual hook.
|
|
21
21
|
/// Each ALLOWANCE block grants or updates a host-scoped asset cap. Only callable by the admin account.
|
|
22
22
|
abstract contract Allowance is AdminBase, AllowanceHook {
|
|
23
|
-
|
|
23
|
+
bytes32 private immutable descriptor;
|
|
24
24
|
|
|
25
25
|
constructor() {
|
|
26
|
-
|
|
27
|
-
emit Labeled(allowanceId, bytes32(0), "allowance");
|
|
26
|
+
(, descriptor) = command("allowance", Keys.Empty, Keys.Allowance, Keys.Empty, 0, false, true);
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
/// @notice Apply each ALLOWANCE block in the admin request.
|
|
31
|
-
/// @param c Admin command context; `c.
|
|
30
|
+
/// @param c Admin command context; `c.input` must contain ALLOWANCE blocks.
|
|
32
31
|
/// @return Empty output state.
|
|
33
32
|
function allowance(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory) {
|
|
34
|
-
(Cur memory
|
|
33
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
35
34
|
|
|
36
|
-
while (
|
|
37
|
-
(uint peer, bytes32 asset, uint amount) =
|
|
35
|
+
while (input.i < input.len) {
|
|
36
|
+
(uint peer, bytes32 asset, uint amount) = input.unpackAllowance();
|
|
38
37
|
allowance(peer, asset, amount);
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
request.complete();
|
|
42
39
|
return "";
|
|
43
40
|
}
|
|
44
41
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import { AdminBase, CommandContext, Keys } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur
|
|
5
|
+
import { Cursors, Cur } from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
/// @title Appoint
|
|
@@ -10,27 +10,24 @@ using Cursors for Cur;
|
|
|
10
10
|
/// Each ACCOUNT block in the request is enabled as a guardian on the host.
|
|
11
11
|
/// Only callable by the admin account.
|
|
12
12
|
abstract contract Appoint is AdminBase {
|
|
13
|
-
|
|
13
|
+
bytes32 private immutable descriptor;
|
|
14
14
|
|
|
15
15
|
constructor() {
|
|
16
|
-
|
|
17
|
-
emit Labeled(appointId, bytes32(0), "appoint");
|
|
16
|
+
(, descriptor) = command("appoint", Keys.Empty, Keys.Account, Keys.Empty, 0, false, true);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/// @notice Appoint each ACCOUNT block in the admin request as a guardian.
|
|
21
|
-
/// @param c Admin command context; `c.
|
|
20
|
+
/// @param c Admin command context; `c.input` must contain ACCOUNT blocks.
|
|
22
21
|
/// @return Empty output state.
|
|
23
22
|
function appoint(
|
|
24
23
|
CommandContext calldata c
|
|
25
24
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
26
|
-
(Cur memory
|
|
25
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
27
26
|
|
|
28
|
-
while (
|
|
29
|
-
bytes32 account =
|
|
27
|
+
while (input.i < input.len) {
|
|
28
|
+
bytes32 account = input.unpackAccount();
|
|
30
29
|
setGuardian(account, true);
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
request.complete();
|
|
34
31
|
return "";
|
|
35
32
|
}
|
|
36
33
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import {AdminBase, CommandContext, Keys} from "./Base.sol";
|
|
5
|
+
import {Cursors, Cur} from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
/// @title Authorize
|
|
@@ -10,32 +10,23 @@ using Cursors for Cur;
|
|
|
10
10
|
/// Each NODE block in the request is authorized on the host.
|
|
11
11
|
/// Only callable by the admin account.
|
|
12
12
|
abstract contract Authorize is AdminBase {
|
|
13
|
-
|
|
13
|
+
bytes32 private immutable descriptor;
|
|
14
|
+
uint internal immutable authorizeId;
|
|
14
15
|
|
|
15
16
|
constructor() {
|
|
16
|
-
|
|
17
|
-
emit Labeled(authorizeId, bytes32(0), "authorize");
|
|
17
|
+
(authorizeId, descriptor) = command("authorize", Keys.Empty, Keys.Node, Keys.Empty, 0, false, true);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/// @notice Authorize each NODE block in the admin request.
|
|
21
|
-
/// @param c Admin command context; `c.
|
|
21
|
+
/// @param c Admin command context; `c.input` must contain NODE blocks.
|
|
22
22
|
/// @return Empty output state.
|
|
23
|
-
function authorize(
|
|
24
|
-
|
|
25
|
-
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
26
|
-
(Cur memory request, ) = Cursors.init(c.request, 1);
|
|
23
|
+
function authorize(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory) {
|
|
24
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
27
25
|
|
|
28
|
-
while (
|
|
29
|
-
uint node =
|
|
26
|
+
while (input.i < input.len) {
|
|
27
|
+
uint node = input.unpackNode();
|
|
30
28
|
setNode(node, true);
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
request.complete();
|
|
34
30
|
return "";
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
package/commands/admin/Base.sol
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import {CommandBase, CommandContext, Keys} from "../Base.sol";
|
|
5
|
-
import {AdminEvent} from "../../events/Admin.sol";
|
|
6
5
|
|
|
7
6
|
/// @title AdminBase
|
|
8
7
|
/// @notice Shared base for admin commands.
|
|
9
|
-
abstract contract AdminBase is CommandBase
|
|
8
|
+
abstract contract AdminBase is CommandBase {}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import { AdminBase, CommandContext, Keys } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur
|
|
5
|
+
import { Cursors, Cur } from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
abstract contract DenyAssetsHook {
|
|
@@ -16,27 +16,24 @@ abstract contract DenyAssetsHook {
|
|
|
16
16
|
/// @notice Admin command that blocks a list of assets via a virtual hook.
|
|
17
17
|
/// Each ASSET block in the request calls `denyAsset`. Only callable by the admin account.
|
|
18
18
|
abstract contract DenyAssets is AdminBase, DenyAssetsHook {
|
|
19
|
-
|
|
19
|
+
bytes32 private immutable descriptor;
|
|
20
20
|
|
|
21
21
|
constructor() {
|
|
22
|
-
|
|
23
|
-
emit Labeled(denyAssetsId, bytes32(0), "denyAssets");
|
|
22
|
+
(, descriptor) = command("denyAssets", Keys.Empty, Keys.Asset, Keys.Empty, 0, false, true);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
/// @notice Deny each ASSET block in the admin request.
|
|
27
|
-
/// @param c Admin command context; `c.
|
|
26
|
+
/// @param c Admin command context; `c.input` must contain ASSET blocks.
|
|
28
27
|
/// @return Empty output state.
|
|
29
28
|
function denyAssets(
|
|
30
29
|
CommandContext calldata c
|
|
31
30
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
32
|
-
(Cur memory
|
|
31
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
33
32
|
|
|
34
|
-
while (
|
|
35
|
-
bytes32 asset =
|
|
33
|
+
while (input.i < input.len) {
|
|
34
|
+
bytes32 asset = input.unpackAsset();
|
|
36
35
|
denyAsset(asset);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
request.complete();
|
|
40
37
|
return "";
|
|
41
38
|
}
|
|
42
39
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import { AdminBase, CommandContext, Keys } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur
|
|
5
|
+
import { Cursors, Cur } from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
/// @title Dismiss
|
|
@@ -10,27 +10,24 @@ using Cursors for Cur;
|
|
|
10
10
|
/// Each ACCOUNT block in the request is disabled as a guardian on the host.
|
|
11
11
|
/// Only callable by the admin account.
|
|
12
12
|
abstract contract Dismiss is AdminBase {
|
|
13
|
-
|
|
13
|
+
bytes32 private immutable descriptor;
|
|
14
14
|
|
|
15
15
|
constructor() {
|
|
16
|
-
|
|
17
|
-
emit Labeled(dismissId, bytes32(0), "dismiss");
|
|
16
|
+
(, descriptor) = command("dismiss", Keys.Empty, Keys.Account, Keys.Empty, 0, false, true);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/// @notice Dismiss each ACCOUNT block in the admin request from guardian status.
|
|
21
|
-
/// @param c Admin command context; `c.
|
|
20
|
+
/// @param c Admin command context; `c.input` must contain ACCOUNT blocks.
|
|
22
21
|
/// @return Empty output state.
|
|
23
22
|
function dismiss(
|
|
24
23
|
CommandContext calldata c
|
|
25
24
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
26
|
-
(Cur memory
|
|
25
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
27
26
|
|
|
28
|
-
while (
|
|
29
|
-
bytes32 account =
|
|
27
|
+
while (input.i < input.len) {
|
|
28
|
+
bytes32 account = input.unpackAccount();
|
|
30
29
|
setGuardian(account, false);
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
request.complete();
|
|
34
31
|
return "";
|
|
35
32
|
}
|
|
36
33
|
}
|
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import {AdminBase, CommandContext, Keys} from "./Base.sol";
|
|
5
5
|
import {Payable} from "../../core/Payable.sol";
|
|
6
|
-
import {Cursors, Cur
|
|
6
|
+
import {Cursors, Cur} from "../../Cursors.sol";
|
|
7
7
|
import {Budget} from "../../utils/Value.sol";
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
@@ -14,26 +14,23 @@ using Cursors for Cur;
|
|
|
14
14
|
/// Only callable by the admin account.
|
|
15
15
|
/// Unspent top-level `msg.value` remains on this host.
|
|
16
16
|
abstract contract ExecutePayable is AdminBase, Payable {
|
|
17
|
-
|
|
17
|
+
bytes32 private immutable descriptor;
|
|
18
18
|
|
|
19
19
|
constructor() {
|
|
20
|
-
|
|
21
|
-
emit Labeled(executePayableId, bytes32(0), "executePayable");
|
|
20
|
+
(, descriptor) = command("executePayable", Keys.Empty, Keys.Call, Keys.Empty, 0, true, true);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
/// @notice Execute each CALL block in the admin request.
|
|
25
|
-
/// @param c Admin command context; `c.
|
|
24
|
+
/// @param c Admin command context; `c.input` must contain CALL blocks.
|
|
26
25
|
/// @return Empty output state.
|
|
27
26
|
function executePayable(CommandContext calldata c) external payable onlyAdmin(c.account) returns (bytes memory) {
|
|
28
|
-
(Cur memory
|
|
27
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
29
28
|
Budget memory budget = openValue();
|
|
30
29
|
|
|
31
|
-
while (
|
|
32
|
-
(uint target, uint resources, bytes calldata data) =
|
|
30
|
+
while (input.i < input.len) {
|
|
31
|
+
(uint target, uint resources, bytes calldata data) = input.unpackCall();
|
|
33
32
|
rawCall(target, useValue(budget, resources), data);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
request.complete();
|
|
37
34
|
return "";
|
|
38
35
|
}
|
|
39
36
|
}
|
package/commands/admin/Label.sol
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import {AdminBase, CommandContext, Keys} from "./Base.sol";
|
|
5
|
-
import {Cursors, Cur
|
|
5
|
+
import {Cursors, Cur} from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
/// @title Label
|
|
@@ -10,25 +10,22 @@ using Cursors for Cur;
|
|
|
10
10
|
/// Each LABEL block in the request emits one `Labeled` event. Only callable by
|
|
11
11
|
/// the admin account.
|
|
12
12
|
abstract contract Label is AdminBase {
|
|
13
|
-
|
|
13
|
+
bytes32 private immutable descriptor;
|
|
14
14
|
|
|
15
15
|
constructor() {
|
|
16
|
-
|
|
17
|
-
emit Labeled(labelId, bytes32(0), "label");
|
|
16
|
+
(, descriptor) = command("label", Keys.Empty, Keys.Label, Keys.Empty, 0, false, true);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/// @notice Publish each LABEL block in the admin request.
|
|
21
|
-
/// @param c Admin command context; `c.
|
|
20
|
+
/// @param c Admin command context; `c.input` must contain LABEL blocks.
|
|
22
21
|
/// @return Empty output state.
|
|
23
22
|
function label(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory) {
|
|
24
|
-
(Cur memory
|
|
23
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
25
24
|
|
|
26
|
-
while (
|
|
27
|
-
(uint
|
|
28
|
-
emit Labeled(
|
|
25
|
+
while (input.i < input.len) {
|
|
26
|
+
(uint node, bytes32 namespace, string memory name) = input.unpackLabel();
|
|
27
|
+
emit Labeled(node, namespace, name);
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
request.complete();
|
|
32
29
|
return "";
|
|
33
30
|
}
|
|
34
31
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AdminBase, CommandContext, Keys} from "./Base.sol";
|
|
5
|
+
import {Cursors, Cur} from "../../Cursors.sol";
|
|
6
|
+
using Cursors for Cur;
|
|
7
|
+
|
|
8
|
+
/// @title PublishSchema
|
|
9
|
+
/// @notice Admin command that publishes block schemas for keys.
|
|
10
|
+
/// Each SCHEMA block in the request emits one `Schema` event. Only callable by
|
|
11
|
+
/// the admin account.
|
|
12
|
+
abstract contract PublishSchema is AdminBase {
|
|
13
|
+
bytes32 private immutable descriptor;
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
(, descriptor) = command("publishSchema", Keys.Empty, Keys.Schema, Keys.Empty, 0, false, true);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// @notice Publish each SCHEMA block in the admin request.
|
|
20
|
+
/// @param c Admin command context; `c.input` must contain SCHEMA blocks.
|
|
21
|
+
/// @return Empty output state.
|
|
22
|
+
function publishSchema(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory) {
|
|
23
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
24
|
+
|
|
25
|
+
while (input.i < input.len) {
|
|
26
|
+
(bytes4 key, string memory body, bytes32 name) = input.unpackSchema();
|
|
27
|
+
emit Schema(host, key, body, name);
|
|
28
|
+
}
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import {AdminBase, CommandContext, Keys} from "./Base.sol";
|
|
5
|
+
import {Cursors, Cur} from "../../Cursors.sol";
|
|
6
6
|
using Cursors for Cur;
|
|
7
7
|
|
|
8
8
|
/// @title Unauthorize
|
|
@@ -10,32 +10,23 @@ using Cursors for Cur;
|
|
|
10
10
|
/// Each NODE block in the request is deauthorized on the host.
|
|
11
11
|
/// Only callable by the admin account.
|
|
12
12
|
abstract contract Unauthorize is AdminBase {
|
|
13
|
-
|
|
13
|
+
bytes32 private immutable descriptor;
|
|
14
|
+
uint internal immutable unauthorizeId;
|
|
14
15
|
|
|
15
16
|
constructor() {
|
|
16
|
-
|
|
17
|
-
emit Labeled(unauthorizeId, bytes32(0), "unauthorize");
|
|
17
|
+
(unauthorizeId, descriptor) = command("unauthorize", Keys.Empty, Keys.Node, Keys.Empty, 0, false, true);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/// @notice Unauthorize each NODE block in the admin request.
|
|
21
|
-
/// @param c Admin command context; `c.
|
|
21
|
+
/// @param c Admin command context; `c.input` must contain NODE blocks.
|
|
22
22
|
/// @return Empty output state.
|
|
23
|
-
function unauthorize(
|
|
24
|
-
|
|
25
|
-
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
26
|
-
(Cur memory request, ) = Cursors.init(c.request, 1);
|
|
23
|
+
function unauthorize(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory) {
|
|
24
|
+
(Cur memory input, ) = openInput(c.input, descriptor);
|
|
27
25
|
|
|
28
|
-
while (
|
|
29
|
-
uint node =
|
|
26
|
+
while (input.i < input.len) {
|
|
27
|
+
uint node = input.unpackNode();
|
|
30
28
|
setNode(node, false);
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
request.complete();
|
|
34
30
|
return "";
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|