fil_actor_paych_state/v10/state.rs
1// Copyright 2019-2022 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use cid::Cid;
5use fvm_ipld_encoding::tuple::*;
6use fvm_shared3::address::Address;
7
8use fvm_shared3::clock::ChainEpoch;
9use fvm_shared3::econ::TokenAmount;
10
11/// A given payment channel actor is established by `from`
12/// to enable off-chain micro-transactions to `to` address
13/// to be reconciled and tallied on chain.
14#[derive(Debug, Serialize_tuple, Deserialize_tuple, Clone)]
15pub struct State {
16 /// Channel owner, who has funded the actor.
17 pub from: Address,
18 /// Recipient of payouts from channel.
19 pub to: Address,
20 /// Amount successfully redeemed through the payment channel, paid out on `Collect`.
21 pub to_send: TokenAmount,
22 /// Height at which the channel can be collected.
23 pub settling_at: ChainEpoch,
24 /// Height before which the channel `ToSend` cannot be collected.
25 pub min_settle_height: ChainEpoch,
26 /// Collections of lane states for the channel, maintained in ID order.
27 pub lane_states: Cid, // AMT<LaneState>
28}
29
30impl State {
31 pub fn new(from: Address, to: Address, empty_arr_cid: Cid) -> Self {
32 Self {
33 from,
34 to,
35 to_send: Default::default(),
36 settling_at: 0,
37 min_settle_height: 0,
38 lane_states: empty_arr_cid,
39 }
40 }
41}
42
43/// The Lane state tracks the latest (highest) voucher nonce used to merge the lane
44/// as well as the amount it has already redeemed.
45#[derive(Default, Clone, PartialEq, Eq, Debug, Serialize_tuple, Deserialize_tuple)]
46pub struct LaneState {
47 pub redeemed: TokenAmount,
48 pub nonce: u64,
49}
50
51/// Specifies which `lane`s to be merged with what `nonce` on `channel_update`
52#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
53pub struct Merge {
54 pub lane: u64,
55 pub nonce: u64,
56}