-
Notifications
You must be signed in to change notification settings - Fork 17
Fungible Tokens (spike) #1
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6f5714b
tidy fvm_dispatch
alexytsu 4eb159f
define token interfaces
alexytsu b14b584
basic token functionality
alexytsu 56df558
author an actor that uses fil_token
alexytsu 788f80d
better params and return types
alexytsu 18759e2
cleanup
alexytsu 2075285
cleaner error handling
alexytsu 2750b24
add readme for token example actor
alexytsu 9383f3a
remove mint from token interface
alexytsu 950d95d
integration test
alexytsu cbeccf8
non-running integration tests
alexytsu 870b3ff
clippy fixes
alexytsu dc3eb69
revert dependency overrides
alexytsu f7efed9
add docs; separate api interface from library interface
alexytsu 94efb15
wip: test
alexytsu dc97abf
Merge branch 'main' into token/spike
alexytsu e686791
hide ipld data structures behind the state abstraction
alexytsu 2008cbd
refactor allowance code
alexytsu 400f2f1
finish core implementation of frc-xxx token
alexytsu 258e2ae
failing tests
alexytsu ccfb79b
HACK: save changes into blockstore properly for some operations
alexytsu 74e6738
remove unecessary runtime abstraction
alexytsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ Cargo.lock | |
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
.vscode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[workspace] | ||
|
||
members = [ | ||
"fvm_dispatch", | ||
"fil_token", | ||
"testing/fil_token_integration", | ||
"testing/fil_token_integration/actors/wfil_token_actor", | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "fil_token" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
anyhow = "1.0.56" | ||
cid = { version = "0.8.3", default-features = false, features = ["serde-codec"] } | ||
fvm_ipld_blockstore = "0.1.1" | ||
fvm_ipld_hamt = "0.5.1" | ||
fvm_ipld_amt = { version = "0.4.2", features = ["go-interop"] } | ||
fvm_ipld_encoding = "0.2.2" | ||
fvm_sdk = { version = "1.0.0" } | ||
fvm_shared = { version = "0.8.0" } | ||
serde = { version = "1.0.136", features = ["derive"] } | ||
serde_tuple = { version = "0.5.0" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::convert::TryFrom; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use cid::multihash::Code; | ||
use cid::Cid; | ||
use fvm_ipld_blockstore::Block; | ||
use fvm_sdk::ipld; | ||
|
||
/// A blockstore that delegates to IPLD syscalls. | ||
#[derive(Default, Debug, Copy, Clone)] | ||
pub struct Blockstore; | ||
|
||
impl fvm_ipld_blockstore::Blockstore for Blockstore { | ||
alexytsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn get(&self, cid: &Cid) -> Result<Option<Vec<u8>>> { | ||
// If this fails, the _CID_ is invalid. I.e., we have a bug. | ||
ipld::get(cid) | ||
.map(Some) | ||
.map_err(|e| anyhow!("get failed with {:?} on CID '{}'", e, cid)) | ||
} | ||
|
||
fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()> { | ||
let code = Code::try_from(k.hash().code()).map_err(|e| anyhow!(e.to_string()))?; | ||
let k2 = self.put(code, &Block::new(k.codec(), block))?; | ||
if k != &k2 { | ||
return Err(anyhow!("put block with cid {} but has cid {}", k, k2)); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn put<D>(&self, code: Code, block: &Block<D>) -> Result<Cid> | ||
where | ||
D: AsRef<[u8]>, | ||
{ | ||
// TODO: Don't hard-code the size. Unfortunately, there's no good way to get it from the | ||
// codec at the moment. | ||
const SIZE: u32 = 32; | ||
let k = ipld::put(code.into(), SIZE, block.codec, block.data.as_ref()) | ||
.map_err(|e| anyhow!("put failed with {:?}", e))?; | ||
Ok(k) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub mod blockstore; | ||
pub mod runtime; | ||
pub mod token; | ||
|
||
#[cfg(test)] | ||
mod tests {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use super::Runtime; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use fvm_sdk as sdk; | ||
use sdk::actor; | ||
use sdk::message; | ||
|
||
pub struct FvmRuntime {} | ||
alexytsu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
impl Runtime for FvmRuntime { | ||
fn caller(&self) -> u64 { | ||
message::caller() | ||
} | ||
|
||
fn resolve_address(&self, addr: &fvm_shared::address::Address) -> Result<u64> { | ||
actor::resolve_address(addr).ok_or_else(|| anyhow!("Failed to resolve address")) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod fvm; | ||
pub use fvm::*; | ||
|
||
use anyhow::Result; | ||
use fvm_shared::address::Address; | ||
|
||
pub trait Runtime { | ||
alexytsu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
fn caller(&self) -> u64; | ||
|
||
fn resolve_address(&self, addr: &Address) -> Result<u64>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::{error::Error, fmt::Display}; | ||
|
||
use fvm_ipld_hamt::Error as HamtError; | ||
use fvm_shared::address::Address; | ||
|
||
#[derive(Debug)] | ||
pub enum RuntimeError { | ||
AddrNotFound(Address), | ||
} | ||
|
||
impl Display for RuntimeError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
RuntimeError::AddrNotFound(_) => write!(f, "Address not found"), | ||
} | ||
} | ||
} | ||
|
||
impl Error for RuntimeError {} | ||
|
||
#[derive(Debug)] | ||
pub enum StateError {} | ||
|
||
impl Display for StateError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "State error") | ||
} | ||
} | ||
|
||
impl Error for StateError {} | ||
|
||
#[derive(Debug)] | ||
pub enum ActorError { | ||
AddrNotFound(Address), | ||
Arithmetic(String), | ||
IpldState(StateError), | ||
IpldHamt(HamtError), | ||
RuntimeError(RuntimeError), | ||
} | ||
|
||
impl Display for ActorError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
ActorError::AddrNotFound(e) => write!(f, "{}", e), | ||
ActorError::Arithmetic(e) => write!(f, "{}", e), | ||
ActorError::IpldState(e) => write!(f, "{}", e), | ||
ActorError::IpldHamt(e) => write!(f, "{}", e), | ||
ActorError::RuntimeError(e) => write!(f, "{}", e), | ||
} | ||
} | ||
} | ||
|
||
impl Error for ActorError {} | ||
|
||
impl From<StateError> for ActorError { | ||
fn from(e: StateError) -> Self { | ||
Self::IpldState(e) | ||
} | ||
} | ||
|
||
impl From<HamtError> for ActorError { | ||
fn from(e: HamtError) -> Self { | ||
Self::IpldHamt(e) | ||
} | ||
} | ||
|
||
impl From<RuntimeError> for ActorError { | ||
fn from(e: RuntimeError) -> Self { | ||
ActorError::RuntimeError(e) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.