Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all 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
76 changes: 50 additions & 26 deletions Cargo.lock

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

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ incremental = false
#many-server = { path = "../many-rs/src/many-server" }
#many-types = { path = "../many-rs/src/many-types" }

[patch."https://github.com/liftedinit/many-rs.git"]
many = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-client = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-client-macros = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-error = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-identity = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-identity-dsa = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-identity-hsm = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-identity-webauthn = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-macros = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-migration = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-mock = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-modules = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-protocol = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-server = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }
many-types = { git = "https://github.com/MavenRain/many-rs/", branch = "oobi/proof" }

[patch.crates-io]
ciborium = { git = "https://github.com/enarx/ciborium", rev = "2ca375e6b33d1ade5a5798792278b35a807b748e" }
ciborium-io = { git = "https://github.com/enarx/ciborium", rev = "2ca375e6b33d1ade5a5798792278b35a807b748e" }
1 change: 1 addition & 0 deletions src/many-ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ name = "many-ledger"
doc = false

[dependencies]
async-channel = "1.8"
async-trait = "0.1.51"
base64 = "0.20.0-alpha.1"
bip39-dict = "0.1"
Expand Down
13 changes: 8 additions & 5 deletions src/many-ledger/src/module/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::module::LedgerModuleImpl;
use many_error::ManyError;
use many_identity::Address;
use many_modules::ledger;
use many_protocol::context::Context;
use std::collections::BTreeSet;
use tracing::info;

Expand Down Expand Up @@ -34,17 +35,19 @@ impl ledger::LedgerModuleBackend for LedgerModuleImpl {
fn balance(
&self,
sender: &Address,
args: ledger::BalanceArgs,
ledger::BalanceArgs { account, symbols }: ledger::BalanceArgs,
context: Context,
) -> Result<ledger::BalanceReturns, ManyError> {
let ledger::BalanceArgs { account, symbols } = args;

let identity = account.as_ref().unwrap_or(sender);

let storage = &self.storage;
let symbols = symbols.unwrap_or_default().0;

let balances = storage
.get_multiple_balances(identity, &BTreeSet::from_iter(symbols.clone().into_iter()))?;
let balances = storage.get_multiple_balances(
identity,
&BTreeSet::from_iter(symbols.clone().into_iter()),
context,
)?;
info!("balance({}, {:?}): {:?}", identity, &symbols, &balances);
Ok(ledger::BalanceReturns { balances })
}
Expand Down
12 changes: 8 additions & 4 deletions src/many-ledger/src/module/ledger_mintburn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ use many_identity::Address;
use many_modules::events::EventInfo;
use many_modules::ledger;
use many_modules::ledger::{TokenBurnArgs, TokenBurnReturns, TokenMintArgs, TokenMintReturns};
use many_protocol::context::Context;
use many_types::ledger::Symbol;
use std::collections::BTreeSet;

/// Check if a symbol exists in the storage
fn check_symbol_exists(symbol: &Symbol, symbols: BTreeSet<Symbol>) -> Result<(), ManyError> {
if !symbols.contains(symbol) {
return Err(error::symbol_not_found(symbol.to_string()));
Err(error::symbol_not_found(symbol.to_string()))
} else {
Ok(())
}
Ok(())
}

impl ledger::LedgerMintBurnModuleBackend for LedgerModuleImpl {
fn mint(
&mut self,
sender: &Address,
args: TokenMintArgs,
context: Context,
) -> Result<TokenMintReturns, ManyError> {
if !self.storage.migrations().is_active(&TOKEN_MIGRATION) {
return Err(ManyError::invalid_method_name("tokens.mint"));
Expand All @@ -44,7 +47,7 @@ impl ledger::LedgerMintBurnModuleBackend for LedgerModuleImpl {
check_symbol_exists(&symbol, self.storage.get_symbols()?)?;

// Mint into storage
self.storage.mint_token(symbol, &distribution)?;
self.storage.mint_token(symbol, &distribution, context)?;

// Log event
self.storage.log_event(EventInfo::TokenMint {
Expand All @@ -60,6 +63,7 @@ impl ledger::LedgerMintBurnModuleBackend for LedgerModuleImpl {
&mut self,
sender: &Address,
args: TokenBurnArgs,
context: Context,
) -> Result<TokenBurnReturns, ManyError> {
if !self.storage.migrations().is_active(&TOKEN_MIGRATION) {
return Err(ManyError::invalid_method_name("tokens.burn"));
Expand Down Expand Up @@ -89,7 +93,7 @@ impl ledger::LedgerMintBurnModuleBackend for LedgerModuleImpl {
}

// Burn from storage
self.storage.burn_token(symbol, &distribution)?;
self.storage.burn_token(symbol, &distribution, context)?;

// Log event
self.storage.log_event(EventInfo::TokenBurn {
Expand Down
Loading