fix drk broken by last commit

This commit is contained in:
zero
2024-02-02 15:53:27 +01:00
parent 821ba475d7
commit 71ec264e1d
10 changed files with 41 additions and 28 deletions

View File

@@ -42,8 +42,8 @@ use darkfi_sdk::{
crypto::{
poseidon_hash,
util::{fp_mod_fv, fp_to_u64},
Keypair, MerkleNode, MerkleTree, PublicKey, SecretKey, TokenId, DAO_CONTRACT_ID,
MONEY_CONTRACT_ID,
FuncId, FuncRef, Keypair, MerkleNode, MerkleTree, PublicKey, SecretKey, TokenId,
DAO_CONTRACT_ID, MONEY_CONTRACT_ID,
},
pasta::pallas,
ContractCall,
@@ -1175,8 +1175,12 @@ impl Drk {
return Err(Error::RusqliteError(format!("DAO with ID {dao_id} not found in wallet")))
};
let dao_spend_hook =
FuncRef { contract_id: *DAO_CONTRACT_ID, func_code: DaoFunction::Exec as u8 }
.to_func_id();
let mut coins = self.get_coins(false).await?;
coins.retain(|x| x.0.note.spend_hook == DAO_CONTRACT_ID.inner());
coins.retain(|x| x.0.note.spend_hook == dao_spend_hook);
coins.retain(|x| x.0.note.user_data == dao.bulla().inner());
// Fill this map with balances
@@ -1401,10 +1405,14 @@ impl Drk {
let bulla = dao.bulla();
let owncoins = self.get_coins(false).await?;
let dao_spend_hook =
FuncRef { contract_id: *DAO_CONTRACT_ID, func_code: DaoFunction::Exec as u8 }
.to_func_id();
let mut dao_owncoins: Vec<OwnCoin> = owncoins.iter().map(|x| x.0.clone()).collect();
dao_owncoins.retain(|x| {
x.note.token_id == token_id &&
x.note.spend_hook == DAO_CONTRACT_ID.inner() &&
x.note.spend_hook == dao_spend_hook &&
x.note.user_data == bulla.inner()
});
@@ -1600,7 +1608,7 @@ impl Drk {
self.get_coins(false).await?.iter().map(|x| x.0.clone()).collect();
coins.retain(|x| x.note.token_id == dao.gov_token_id);
coins.retain(|x| x.note.spend_hook == pallas::Base::zero());
coins.retain(|x| x.note.spend_hook == FuncId::none());
if coins.iter().map(|x| x.note.value).sum::<u64>() < weight {
return Err(Error::Custom("[dao_vote] Not enough balance for vote weight".to_string()))

View File

@@ -44,7 +44,7 @@ use darkfi::{
};
use darkfi_money_contract::model::Coin;
use darkfi_sdk::{
crypto::{PublicKey, SecretKey, TokenId},
crypto::{FuncId, PublicKey, SecretKey, TokenId},
pasta::{group::ff::PrimeField, pallas},
};
use darkfi_serial::{deserialize, serialize};
@@ -747,20 +747,21 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
"Spend Hook",
"User Data"
]);
let zero = pallas::Base::zero();
for coin in coins {
let aliases = match aliases_map.get(&coin.0.note.token_id.to_string()) {
Some(a) => a,
None => "-",
};
let spend_hook = if coin.0.note.spend_hook != zero {
bs58::encode(&serialize(&coin.0.note.spend_hook)).into_string().to_string()
let spend_hook = if coin.0.note.spend_hook != FuncId::none() {
bs58::encode(&serialize(&coin.0.note.spend_hook.inner()))
.into_string()
.to_string()
} else {
String::from("-")
};
let user_data = if coin.0.note.user_data != zero {
let user_data = if coin.0.note.user_data != pallas::Base::ZERO {
bs58::encode(&serialize(&coin.0.note.user_data)).into_string().to_string()
} else {
String::from("-")

View File

@@ -31,7 +31,7 @@ use darkfi_money_contract::{
use darkfi_sdk::{
bridgetree,
crypto::{
note::AeadEncryptedNote, poseidon_hash, Keypair, MerkleNode, MerkleTree, Nullifier,
note::AeadEncryptedNote, poseidon_hash, FuncId, Keypair, MerkleNode, MerkleTree, Nullifier,
PublicKey, SecretKey, TokenId, MONEY_CONTRACT_ID,
},
pasta::pallas,
@@ -351,7 +351,7 @@ impl Drk {
/// Fetch known unspent balances from the wallet and return them as a hashmap.
pub async fn money_balance(&self) -> Result<HashMap<String, u64>> {
let mut coins = self.get_coins(false).await?;
coins.retain(|x| x.0.note.spend_hook == pallas::Base::zero());
coins.retain(|x| x.0.note.spend_hook == FuncId::none());
// Fill this map with balances
let mut balmap: HashMap<String, u64> = HashMap::new();
@@ -467,7 +467,7 @@ impl Drk {
let note = MoneyNote {
value,
token_id,
spend_hook,
spend_hook: spend_hook.into(),
user_data,
coin_blind,
value_blind,

View File

@@ -33,7 +33,7 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{
contract_id::MONEY_CONTRACT_ID, pedersen::pedersen_commitment_u64, poseidon_hash,
contract_id::MONEY_CONTRACT_ID, pedersen::pedersen_commitment_u64, poseidon_hash, FuncId,
PublicKey, SecretKey, TokenId,
},
pasta::pallas,
@@ -83,7 +83,7 @@ impl Drk {
owncoins.retain(|x| {
x.0.note.value == value_send &&
x.0.note.token_id == token_send &&
x.0.note.spend_hook == pallas::Base::zero()
x.0.note.spend_hook == FuncId::none()
});
if owncoins.is_empty() {
@@ -139,8 +139,8 @@ impl Drk {
value_recv,
token_id_recv: token_recv,
user_data_blind_send: pallas::Base::random(&mut OsRng), // <-- FIXME: Perhaps should be passed in
spend_hook_recv: pallas::Base::zero(), // <-- FIXME: Should be passed in
user_data_recv: pallas::Base::zero(), // <-- FIXME: Should be passed in
spend_hook_recv: FuncId::none(), // <-- FIXME: Should be passed in
user_data_recv: pallas::Base::zero(), // <-- FIXME: Should be passed in
value_blinds,
token_blinds,
coin: burn_coin,
@@ -229,8 +229,8 @@ impl Drk {
value_recv: partial.value_pair.0,
token_id_recv: partial.token_pair.0,
user_data_blind_send: pallas::Base::random(&mut OsRng), // <-- FIXME: Perhaps should be passed in
spend_hook_recv: pallas::Base::zero(), // <-- FIXME: Should be passed in
user_data_recv: pallas::Base::zero(), // <-- FIXME: Should be passed in
spend_hook_recv: FuncId::none(), // <-- FIXME: Should be passed in
user_data_recv: pallas::Base::ZERO, // <-- FIXME: Should be passed in
value_blinds: [partial.value_blinds[1], partial.value_blinds[0]],
token_blinds: [partial.token_blinds[1], partial.token_blinds[0]],
coin: burn_coin,

View File

@@ -37,8 +37,8 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{
contract_id::MONEY_CONTRACT_ID, pasta_prelude::*, FuncRef, Keypair, PublicKey, SecretKey,
TokenId,
contract_id::MONEY_CONTRACT_ID, pasta_prelude::*, FuncId, FuncRef, Keypair, PublicKey,
SecretKey, TokenId,
},
dark_tree::DarkLeaf,
pasta::pallas,
@@ -120,7 +120,7 @@ impl Drk {
token_attrs: TokenAttributes,
) -> Result<Transaction> {
// TODO: Mint directly into DAO treasury
let spend_hook = pallas::Base::zero();
let spend_hook = FuncId::none();
let user_data = pallas::Base::zero();
let amount = decode_base10(amount, BALANCE_BASE10_DECIMALS, false)?;

View File

@@ -30,8 +30,7 @@ use darkfi_money_contract::{
MoneyFunction, MONEY_CONTRACT_ZKAS_BURN_NS_V1, MONEY_CONTRACT_ZKAS_MINT_NS_V1,
};
use darkfi_sdk::{
crypto::{contract_id::MONEY_CONTRACT_ID, Keypair, PublicKey, TokenId},
pasta::pallas,
crypto::{contract_id::MONEY_CONTRACT_ID, FuncId, Keypair, PublicKey, TokenId},
tx::ContractCall,
};
use darkfi_serial::Encodable;
@@ -53,7 +52,7 @@ impl Drk {
// We're only interested in the ones for the token_id we're sending
// And the ones not owned by some protocol (meaning spend-hook should be 0)
owncoins.retain(|x| x.note.token_id == token_id);
owncoins.retain(|x| x.note.spend_hook == pallas::Base::zero());
owncoins.retain(|x| x.note.spend_hook == FuncId::none());
if owncoins.is_empty() {
return Err(Error::Custom(format!("Did not find any coins with token ID: {token_id}")))
}

View File

@@ -21,7 +21,6 @@ use darkfi_sdk::{
dark_tree::DarkLeaf,
db::{db_init, db_lookup, db_set, zkas_db_set},
error::ContractResult,
msg,
pasta::pallas,
util::set_return_data,
ContractCall,

View File

@@ -18,7 +18,7 @@
use darkfi_sdk::{
crypto::{
pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, ContractId, FuncId, MerkleNode,
pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, ContractId, MerkleNode,
PublicKey, DARK_TOKEN_ID,
},
dark_tree::DarkLeaf,

View File

@@ -17,7 +17,7 @@
*/
use darkfi_sdk::{
crypto::{ContractId, FuncId},
crypto::ContractId,
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup},
error::{ContractError, ContractResult},

View File

@@ -50,3 +50,9 @@ impl FuncId {
self.0
}
}
impl From<pallas::Base> for FuncId {
fn from(func_id: pallas::Base) -> Self {
Self(func_id)
}
}