Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrates datacap token with verified registry actor #514

Merged
merged 5 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions actors/datacap/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::Cbor;
use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::ActorID;

use fil_actors_runtime::{ActorError, AsActorError};

Expand All @@ -19,6 +21,17 @@ impl State {
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to create token state")?;
Ok(State { registry, token: token_state })
}

// Visible for testing
pub fn balance<BS: Blockstore>(
&self,
bs: &BS,
owner: ActorID,
) -> Result<TokenAmount, ActorError> {
self.token
.get_balance(bs, owner)
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to get balance")
}
}

impl Cbor for State {}
9 changes: 6 additions & 3 deletions actors/datacap/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ use crate::State;

pub struct StateSummary {}

/// Checks internal invariants of verified registry state.
/// Checks internal invariants of data cap token actor state.
pub fn check_state_invariants<BS: Blockstore>(
state: &State,
_store: &BS,
store: &BS,
) -> (StateSummary, MessageAccumulator) {
let acc = MessageAccumulator::default();
acc.require(state.registry.protocol() == Protocol::ID, "registry must be ID address");
// TODO: Check invariants in token state.
let r = state.token.check_invariants(store);
if r.is_err() {
acc.add(r.unwrap_err().to_string());
}

(StateSummary {}, acc)
}
44 changes: 44 additions & 0 deletions actors/verifreg/src/ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple};
use fvm_shared::address::Address;
use fvm_shared::bigint::{bigint_ser, BigInt};

pub mod datacap {
use super::*;

// TODO: This constant should be imported from FVM once available there.
pub const TOKEN_PRECISION: u64 = 1_000_000_000_000_000_000;

#[repr(u64)]
pub enum Method {
// Non-standard.
Mint = 2,
Destroy = 3,
ZenGround0 marked this conversation as resolved.
Show resolved Hide resolved
// Static method numbers for token standard methods, for private use.
// Name = 10,
// Symbol = 11,
// TotalSupply = 12,
BalanceOf = 13,
// Transfer = 14,
// TransferFrom = 15,
// IncreaseAllowance = 16,
// DecreaseAllowance = 17,
// RevokeAllowance = 18,
// Burn = 19,
// BurnFrom = 20,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct MintParams {
pub to: Address,
#[serde(with = "bigint_ser")]
pub amount: BigInt,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct DestroyParams {
pub owner: Address,
#[serde(with = "bigint_ser")]
pub amount: BigInt,
}
}
Loading