@rootzero/contracts 1.6.0 → 1.7.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 +34 -1
- package/Endpoints.sol +13 -13
- package/Events.sol +2 -1
- package/README.md +9 -9
- package/blocks/Cursors.sol +36 -49
- package/blocks/Keys.sol +5 -5
- package/blocks/Schema.sol +4 -2
- package/blocks/Writers.sol +0 -35
- package/commands/Deposit.sol +2 -2
- package/commands/Provision.sol +2 -2
- package/commands/Recover.sol +48 -0
- package/commands/Relay.sol +4 -4
- package/commands/admin/Execute.sol +1 -1
- package/core/Commitments.sol +1 -1
- package/core/Payable.sol +15 -28
- package/core/Pipeline.sol +1 -1
- package/docs/Schema.md +13 -2
- package/events/Commitment.sol +4 -4
- package/events/Dispatch.sol +20 -0
- package/events/Port.sol +22 -0
- package/package.json +1 -1
- package/ports/AllowAssets.sol +44 -0
- package/ports/Allowance.sol +41 -0
- package/ports/Base.sol +41 -0
- package/ports/Credit.sol +39 -0
- package/ports/Debit.sol +39 -0
- package/ports/DenyAssets.sol +44 -0
- package/{peer → ports}/Dispatch.sol +13 -13
- package/ports/Pipe.sol +43 -0
- package/{peer → ports}/Redeem.sol +13 -13
- package/ports/Settle.sol +41 -0
- package/utils/Layout.sol +3 -3
- package/utils/Nodes.sol +21 -21
- package/utils/Value.sol +12 -5
- package/events/Peer.sol +0 -22
- package/peer/AllowAssets.sol +0 -44
- package/peer/Allowance.sol +0 -41
- package/peer/Base.sol +0 -41
- package/peer/Credit.sol +0 -39
- package/peer/Debit.sol +0 -39
- package/peer/DenyAssets.sol +0 -44
- package/peer/Pipe.sol +0 -44
- package/peer/Recover.sol +0 -51
- package/peer/Settle.sol +0 -41
package/events/Peer.sol
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
/// @notice Emitted once per peer during host deployment to publish its request and response schemas.
|
|
7
|
-
abstract contract PeerEvent is EventEmitter {
|
|
8
|
-
string private constant ABI =
|
|
9
|
-
"event Peer(uint indexed host, uint id, bytes32 shape, string request, string response, bool funded)";
|
|
10
|
-
|
|
11
|
-
/// @param host Host node ID that owns this peer.
|
|
12
|
-
/// @param id Peer node ID.
|
|
13
|
-
/// @param shape Per-operation block counts encoded as `request:response`.
|
|
14
|
-
/// @param request Schema DSL string describing the input request run, or empty if none.
|
|
15
|
-
/// @param response Schema DSL string describing the peer response shape.
|
|
16
|
-
/// @param funded Whether the peer entrypoint accepts nonzero `msg.value`.
|
|
17
|
-
event Peer(uint indexed host, uint id, bytes32 shape, string request, string response, bool funded);
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
emit EventAbi(ABI);
|
|
21
|
-
}
|
|
22
|
-
}
|
package/peer/AllowAssets.sol
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { PeerBase } from "./Base.sol";
|
|
5
|
-
import { AllowAssetsHook } from "../commands/admin/AllowAssets.sol";
|
|
6
|
-
import { Cursors, Cur, Schemas } from "../Cursors.sol";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
9
|
-
|
|
10
|
-
interface IPeerAllowAssets {
|
|
11
|
-
function peerAllowAssets(bytes calldata request) external returns (bytes memory);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/// @title PeerAllowAssets
|
|
15
|
-
/// @notice Peer that permits a list of assets on behalf of a peer host.
|
|
16
|
-
/// Each ASSET block in the request calls `allowAsset`. Restricted to trusted peers.
|
|
17
|
-
abstract contract PeerAllowAssets is PeerBase, AllowAssetsHook, IPeerAllowAssets {
|
|
18
|
-
uint internal immutable peerAllowAssetsId = peerId(this.peerAllowAssets.selector);
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
emit Peer(host, peerAllowAssetsId, "1:0", Schemas.Asset, "", false);
|
|
22
|
-
emit Labeled(peerAllowAssetsId, bytes32(0), "peerAllowAssets");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/// @notice Execute the allow-assets peer call.
|
|
26
|
-
/// @param request ASSET block stream supplied by the trusted peer.
|
|
27
|
-
/// @return Empty response bytes.
|
|
28
|
-
function peerAllowAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
29
|
-
(Cur memory assets, , ) = Cursors.init(request, 1);
|
|
30
|
-
|
|
31
|
-
while (assets.i < assets.len) {
|
|
32
|
-
bytes32 asset = assets.unpackAsset();
|
|
33
|
-
allowAsset(asset);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
assets.complete();
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
package/peer/Allowance.sol
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {PeerBase} from "./Base.sol";
|
|
5
|
-
import {AllowanceHook} from "../commands/admin/Allowance.sol";
|
|
6
|
-
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
9
|
-
|
|
10
|
-
interface IPeerAllowance {
|
|
11
|
-
function peerAllowance(bytes calldata request) external returns (bytes memory);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/// @title PeerAllowance
|
|
15
|
-
/// @notice Peer that lets a trusted peer host request or refresh its own allowance.
|
|
16
|
-
/// Each AMOUNT block in the request is scoped to the peer host and passed to the
|
|
17
|
-
/// shared allowance hook as a host-scoped allowance. Restricted to trusted peers.
|
|
18
|
-
abstract contract PeerAllowance is PeerBase, AllowanceHook, IPeerAllowance {
|
|
19
|
-
uint internal immutable peerAllowanceId = peerId(this.peerAllowance.selector);
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
emit Peer(host, peerAllowanceId, "1:0", Schemas.Amount, "", false);
|
|
23
|
-
emit Labeled(peerAllowanceId, bytes32(0), "peerAllowance");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/// @notice Execute the allowance peer call.
|
|
27
|
-
/// @param request AMOUNT block stream requested by the trusted peer.
|
|
28
|
-
/// @return Empty response bytes.
|
|
29
|
-
function peerAllowance(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
30
|
-
(Cur memory amounts, , ) = Cursors.init(request, 1);
|
|
31
|
-
uint peer = caller();
|
|
32
|
-
|
|
33
|
-
while (amounts.i < amounts.len) {
|
|
34
|
-
(bytes32 asset, uint amount) = amounts.unpackAmount();
|
|
35
|
-
allowance(peer, asset, amount);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
amounts.complete();
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
}
|
package/peer/Base.sol
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { NodeCalls } from "../core/Calls.sol";
|
|
5
|
-
import { PeerEvent } from "../events/Peer.sol";
|
|
6
|
-
import { LabeledEvent } from "../events/Labeled.sol";
|
|
7
|
-
import { Nodes } from "../utils/Nodes.sol";
|
|
8
|
-
|
|
9
|
-
/// @notice ABI-encode a peer call from a target peer ID and request block stream.
|
|
10
|
-
/// @dev Derives the function selector from `target` via `Nodes.peerSelector(target)`.
|
|
11
|
-
/// Reverts if `target` is not a valid peer ID.
|
|
12
|
-
/// @param target Destination peer node ID embedding the target selector.
|
|
13
|
-
/// @param request Input block stream for the peer invocation.
|
|
14
|
-
/// @return ABI-encoded calldata for the peer entry point.
|
|
15
|
-
function encodePeerCall(uint target, bytes calldata request) pure returns (bytes memory) {
|
|
16
|
-
bytes4 selector = Nodes.peerSelector(target);
|
|
17
|
-
return abi.encodeWithSelector(selector, request);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/// @title PeerBase
|
|
21
|
-
/// @notice Abstract base for all rootzero peer contracts.
|
|
22
|
-
/// Peers handle inter-host operations and asset allow/deny management
|
|
23
|
-
/// between cooperating hosts. Access is restricted to trusted callers via `onlyPeer`.
|
|
24
|
-
abstract contract PeerBase is NodeCalls, PeerEvent, LabeledEvent {
|
|
25
|
-
/// @dev Thrown when the commander attempts to call a peer entrypoint directly.
|
|
26
|
-
error CommanderNotAllowed();
|
|
27
|
-
|
|
28
|
-
/// @dev Restrict execution to trusted callers, excluding the commander.
|
|
29
|
-
modifier onlyPeer() {
|
|
30
|
-
if (msg.sender == commander) revert CommanderNotAllowed();
|
|
31
|
-
enforceCaller(msg.sender);
|
|
32
|
-
_;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/// @notice Derive the deterministic node ID for a peer selector on this contract.
|
|
36
|
-
/// @param selector Peer entrypoint selector.
|
|
37
|
-
/// @return Peer node ID.
|
|
38
|
-
function peerId(bytes4 selector) internal view returns (uint) {
|
|
39
|
-
return Nodes.toPeer(selector, address(this));
|
|
40
|
-
}
|
|
41
|
-
}
|
package/peer/Credit.sol
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { PeerBase } from "./Base.sol";
|
|
5
|
-
import { CreditAccountHook } from "../commands/Credit.sol";
|
|
6
|
-
import { Cursors, Cur, Forms } from "../Cursors.sol";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
9
|
-
|
|
10
|
-
interface IPeerCreditAccount {
|
|
11
|
-
function peerCreditAccount(bytes calldata request) external returns (bytes memory);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/// @title PeerCreditAccount
|
|
15
|
-
/// @notice Peer that lets a trusted peer credit supplied accounts directly.
|
|
16
|
-
/// Each ACCOUNT_AMOUNT block calls `creditAccount` for its account.
|
|
17
|
-
abstract contract PeerCreditAccount is PeerBase, CreditAccountHook, IPeerCreditAccount {
|
|
18
|
-
uint internal immutable peerCreditAccountId = peerId(this.peerCreditAccount.selector);
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
emit Peer(host, peerCreditAccountId, "1:0", Forms.AccountAmount, "", false);
|
|
22
|
-
emit Labeled(peerCreditAccountId, bytes32(0), "peerCreditAccount");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/// @notice Execute the peer-credit call.
|
|
26
|
-
/// @param request ACCOUNT_AMOUNT block stream supplied by the trusted peer.
|
|
27
|
-
/// @return Empty response bytes.
|
|
28
|
-
function peerCreditAccount(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
29
|
-
(Cur memory amounts, , ) = Cursors.init(request, 1);
|
|
30
|
-
|
|
31
|
-
while (amounts.i < amounts.len) {
|
|
32
|
-
(bytes32 account, bytes32 asset, uint amount) = amounts.unpackAccountAmount();
|
|
33
|
-
creditAccount(account, asset, amount);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
amounts.complete();
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
}
|
package/peer/Debit.sol
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { PeerBase } from "./Base.sol";
|
|
5
|
-
import { DebitAccountHook } from "../commands/Debit.sol";
|
|
6
|
-
import { Cursors, Cur, Forms } from "../Cursors.sol";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
9
|
-
|
|
10
|
-
interface IPeerDebitAccount {
|
|
11
|
-
function peerDebitAccount(bytes calldata request) external returns (bytes memory);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/// @title PeerDebitAccount
|
|
15
|
-
/// @notice Peer that lets a trusted peer debit supplied accounts directly.
|
|
16
|
-
/// Each ACCOUNT_AMOUNT block calls `debitAccount` for its account.
|
|
17
|
-
abstract contract PeerDebitAccount is PeerBase, DebitAccountHook, IPeerDebitAccount {
|
|
18
|
-
uint internal immutable peerDebitAccountId = peerId(this.peerDebitAccount.selector);
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
emit Peer(host, peerDebitAccountId, "1:0", Forms.AccountAmount, "", false);
|
|
22
|
-
emit Labeled(peerDebitAccountId, bytes32(0), "peerDebitAccount");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/// @notice Execute the peer-debit call.
|
|
26
|
-
/// @param request ACCOUNT_AMOUNT block stream supplied by the trusted peer.
|
|
27
|
-
/// @return Empty response bytes.
|
|
28
|
-
function peerDebitAccount(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
29
|
-
(Cur memory amounts, , ) = Cursors.init(request, 1);
|
|
30
|
-
|
|
31
|
-
while (amounts.i < amounts.len) {
|
|
32
|
-
(bytes32 account, bytes32 asset, uint amount) = amounts.unpackAccountAmount();
|
|
33
|
-
debitAccount(account, asset, amount);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
amounts.complete();
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
}
|
package/peer/DenyAssets.sol
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {PeerBase} from "./Base.sol";
|
|
5
|
-
import {DenyAssetsHook} from "../commands/admin/DenyAssets.sol";
|
|
6
|
-
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
9
|
-
|
|
10
|
-
interface IPeerDenyAssets {
|
|
11
|
-
function peerDenyAssets(bytes calldata request) external returns (bytes memory);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/// @title PeerDenyAssets
|
|
15
|
-
/// @notice Peer that blocks a list of assets on behalf of a peer host.
|
|
16
|
-
/// Each ASSET block in the request calls `denyAsset`. Restricted to trusted peers.
|
|
17
|
-
abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook, IPeerDenyAssets {
|
|
18
|
-
uint internal immutable peerDenyAssetsId = peerId(this.peerDenyAssets.selector);
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
emit Peer(host, peerDenyAssetsId, "1:0", Schemas.Asset, "", false);
|
|
22
|
-
emit Labeled(peerDenyAssetsId, bytes32(0), "peerDenyAssets");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/// @notice Execute the deny-assets peer call.
|
|
26
|
-
/// @param request ASSET block stream supplied by the trusted peer.
|
|
27
|
-
/// @return Empty response bytes.
|
|
28
|
-
function peerDenyAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
29
|
-
(Cur memory assets, , ) = Cursors.init(request, 1);
|
|
30
|
-
|
|
31
|
-
while (assets.i < assets.len) {
|
|
32
|
-
bytes32 asset = assets.unpackAsset();
|
|
33
|
-
denyAsset(asset);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
assets.complete();
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
package/peer/Pipe.sol
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {PeerBase} from "./Base.sol";
|
|
5
|
-
import {Pipeline} from "../core/Pipeline.sol";
|
|
6
|
-
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
7
|
-
import {Budget} from "../utils/Value.sol";
|
|
8
|
-
|
|
9
|
-
using Cursors for Cur;
|
|
10
|
-
|
|
11
|
-
interface IPeerPipePayable {
|
|
12
|
-
function peerPipePayable(bytes calldata request) external payable returns (bytes memory);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/// @title PeerPipePayable
|
|
16
|
-
/// @notice Peer that consumes PIPE blocks and executes each context step stream.
|
|
17
|
-
/// Each PIPE block carries chain resources plus a CONTEXT block; the nested
|
|
18
|
-
/// context steps are passed to the shared pipeline as the step stream.
|
|
19
|
-
abstract contract PeerPipePayable is PeerBase, Pipeline, IPeerPipePayable {
|
|
20
|
-
uint internal immutable peerPipePayableId = peerId(this.peerPipePayable.selector);
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
emit Peer(host, peerPipePayableId, "1:0", Schemas.Pipe, "", true);
|
|
24
|
-
emit Labeled(peerPipePayableId, bytes32(0), "peerPipePayable");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// @notice Execute peer-supplied pipes through the shared payable pipe.
|
|
28
|
-
/// @dev Each pipe receives its own explicit EVM value sub-budget. Any top-level
|
|
29
|
-
/// `msg.value` not assigned to a pipe remains on this host.
|
|
30
|
-
/// @param request PIPE block stream supplied by the trusted peer.
|
|
31
|
-
/// @return Empty response bytes.
|
|
32
|
-
function peerPipePayable(bytes calldata request) external payable onlyPeer returns (bytes memory) {
|
|
33
|
-
(Cur memory input, , ) = Cursors.init(request, 1);
|
|
34
|
-
Budget memory budget = valueBudget();
|
|
35
|
-
|
|
36
|
-
while (input.i < input.len) {
|
|
37
|
-
(uint resources, bytes32 account, bytes calldata state, bytes calldata steps) = input.unpackPipe();
|
|
38
|
-
pipe(account, state, steps, allocateValue(budget, resources));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
input.complete();
|
|
42
|
-
return "";
|
|
43
|
-
}
|
|
44
|
-
}
|
package/peer/Recover.sol
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {PeerBase} from "./Base.sol";
|
|
5
|
-
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
6
|
-
|
|
7
|
-
using Cursors for Cur;
|
|
8
|
-
|
|
9
|
-
interface IPeerRecover {
|
|
10
|
-
function peerRecover(bytes calldata request) external returns (bytes memory);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
abstract contract RecoverHook {
|
|
14
|
-
/// @notice Override to recover one incoming pipe context from a peer host.
|
|
15
|
-
/// @dev Implementations may refund, retry, compensate, reconcile, or otherwise
|
|
16
|
-
/// handle the supplied state and remaining steps.
|
|
17
|
-
/// @param account Account identifier for the recovery context.
|
|
18
|
-
/// @param state Embedded recovery state block stream.
|
|
19
|
-
/// @param steps Embedded recovery step block stream.
|
|
20
|
-
function recover(bytes32 account, bytes calldata state, bytes calldata steps) internal virtual;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/// @title PeerRecover
|
|
24
|
-
/// @notice Peer endpoint for recovering an interrupted or failed pipe context.
|
|
25
|
-
/// @dev Commonly used when a cross-chain pipe fails at its destination, but the
|
|
26
|
-
/// hook is host-defined and may implement any recovery strategy. Each PIPE
|
|
27
|
-
/// block carries chain resources plus a CONTEXT block; the nested context
|
|
28
|
-
/// is passed to the recovery hook and resources are not allocated.
|
|
29
|
-
abstract contract PeerRecover is PeerBase, RecoverHook, IPeerRecover {
|
|
30
|
-
uint internal immutable peerRecoverId = peerId(this.peerRecover.selector);
|
|
31
|
-
|
|
32
|
-
constructor() {
|
|
33
|
-
emit Peer(host, peerRecoverId, "1:0", Schemas.Pipe, "", false);
|
|
34
|
-
emit Labeled(peerRecoverId, bytes32(0), "peerRecover");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/// @notice Forward peer-supplied recovery pipes to the host-defined recovery hook.
|
|
38
|
-
/// @param request PIPE block stream supplied by the trusted peer.
|
|
39
|
-
/// @return Empty response bytes.
|
|
40
|
-
function peerRecover(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
41
|
-
(Cur memory input, , ) = Cursors.init(request, 1);
|
|
42
|
-
|
|
43
|
-
while (input.i < input.len) {
|
|
44
|
-
(, bytes32 account, bytes calldata state, bytes calldata steps) = input.unpackPipe();
|
|
45
|
-
recover(account, state, steps);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
input.complete();
|
|
49
|
-
return "";
|
|
50
|
-
}
|
|
51
|
-
}
|
package/peer/Settle.sol
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { PeerBase } from "./Base.sol";
|
|
5
|
-
import { CreditAccountHook } from "../commands/Credit.sol";
|
|
6
|
-
import { DebitAccountHook } from "../commands/Debit.sol";
|
|
7
|
-
import { Cursors, Cur, Schemas } from "../Cursors.sol";
|
|
8
|
-
|
|
9
|
-
using Cursors for Cur;
|
|
10
|
-
|
|
11
|
-
interface IPeerSettle {
|
|
12
|
-
function peerSettle(bytes calldata request) external returns (bytes memory);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/// @title PeerSettle
|
|
16
|
-
/// @notice Peer that consumes peer-supplied TRANSACTION blocks through debit and credit hooks.
|
|
17
|
-
/// Each TRANSACTION block calls `debitAccount` for `from` and `creditAccount` for `to`.
|
|
18
|
-
abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook, IPeerSettle {
|
|
19
|
-
uint internal immutable peerSettleId = peerId(this.peerSettle.selector);
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
emit Peer(host, peerSettleId, "1:0", Schemas.Transaction, "", false);
|
|
23
|
-
emit Labeled(peerSettleId, bytes32(0), "peerSettle");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/// @notice Execute the peer-settle call.
|
|
27
|
-
/// @param request TRANSACTION block stream supplied by the trusted peer.
|
|
28
|
-
/// @return Empty response bytes.
|
|
29
|
-
function peerSettle(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
30
|
-
(Cur memory state, , ) = Cursors.init(request, 1);
|
|
31
|
-
|
|
32
|
-
while (state.i < state.len) {
|
|
33
|
-
(bytes32 from, bytes32 to, bytes32 asset, uint amount) = state.unpackTransaction();
|
|
34
|
-
if (from != 0) debitAccount(from, asset, amount);
|
|
35
|
-
if (to != 0) creditAccount(to, asset, amount);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
state.complete();
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
}
|