| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548 |
- /* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2026 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- use std::{collections::HashMap, fmt, str::FromStr};
- use lazy_static::lazy_static;
- use num_bigint::BigUint;
- use rand::rngs::OsRng;
- use rusqlite::types::Value;
- use darkfi::{
- tx::{ContractCallLeaf, Transaction, TransactionBuilder},
- util::{
- encoding::base64,
- parse::{decode_base10, encode_base10},
- },
- zk::{empty_witnesses, halo2::Field, ProvingKey, ZkCircuit},
- zkas::ZkBinary,
- Error, Result,
- };
- use darkfi_dao_contract::{
- blockwindow,
- client::{
- make_mint_call, DaoAuthMoneyTransferCall, DaoExecCall, DaoProposeCall,
- DaoProposeStakeInput, DaoVoteCall, DaoVoteInput,
- },
- model::{
- Dao, DaoAuthCall, DaoBulla, DaoExecParams, DaoMintParams, DaoProposal, DaoProposalBulla,
- DaoProposeParams, DaoVoteParams,
- },
- DaoFunction, DAO_CONTRACT_ZKAS_AUTH_MONEY_TRANSFER_ENC_COIN_NS,
- DAO_CONTRACT_ZKAS_AUTH_MONEY_TRANSFER_NS, DAO_CONTRACT_ZKAS_EARLY_EXEC_NS,
- DAO_CONTRACT_ZKAS_EXEC_NS, DAO_CONTRACT_ZKAS_MINT_NS, DAO_CONTRACT_ZKAS_PROPOSE_INPUT_NS,
- DAO_CONTRACT_ZKAS_PROPOSE_MAIN_NS, DAO_CONTRACT_ZKAS_VOTE_INPUT_NS,
- DAO_CONTRACT_ZKAS_VOTE_MAIN_NS,
- };
- use darkfi_money_contract::{
- client::transfer_v1::{select_coins, TransferCallBuilder, TransferCallInput},
- model::{CoinAttributes, Nullifier, TokenId},
- MoneyFunction, MONEY_CONTRACT_ZKAS_BURN_NS_V1, MONEY_CONTRACT_ZKAS_FEE_NS_V1,
- MONEY_CONTRACT_ZKAS_MINT_NS_V1,
- };
- use darkfi_sdk::{
- bridgetree,
- crypto::{
- keypair::{Address, PublicKey, SecretKey, StandardAddress},
- pasta_prelude::PrimeField,
- poseidon_hash,
- smt::{MemoryStorageFp, PoseidonFp, SmtMemoryFp, EMPTY_NODES_FP},
- util::{fp_mod_fv, fp_to_u64},
- BaseBlind, Blind, FuncId, FuncRef, MerkleNode, MerkleTree, ScalarBlind, DAO_CONTRACT_ID,
- MONEY_CONTRACT_ID,
- },
- dark_tree::DarkTree,
- pasta::pallas,
- tx::TransactionHash,
- ContractCall,
- };
- use darkfi_serial::{
- async_trait, deserialize_async, serialize, serialize_async, AsyncEncodable, SerialDecodable,
- SerialEncodable,
- };
- use crate::{
- cache::{CacheOverlay, CacheSmt, CacheSmtStorage, SLED_MONEY_SMT_TREE},
- convert_named_params,
- error::{WalletDbError, WalletDbResult},
- money::BALANCE_BASE10_DECIMALS,
- rpc::ScanCache,
- Drk,
- };
- // DAO Merkle trees Sled keys
- pub const SLED_MERKLE_TREES_DAO_DAOS: &[u8] = b"_dao_daos";
- pub const SLED_MERKLE_TREES_DAO_PROPOSALS: &[u8] = b"_dao_proposals";
- // Wallet SQL table constant names. These have to represent the `dao.sql`
- // SQL schema. Table names are prefixed with the contract ID to avoid collisions.
- lazy_static! {
- pub static ref DAO_DAOS_TABLE: String = format!("{}_dao_daos", DAO_CONTRACT_ID.to_string());
- pub static ref DAO_COINS_TABLE: String = format!("{}_dao_coins", DAO_CONTRACT_ID.to_string());
- pub static ref DAO_PROPOSALS_TABLE: String =
- format!("{}_dao_proposals", DAO_CONTRACT_ID.to_string());
- pub static ref DAO_VOTES_TABLE: String = format!("{}_dao_votes", DAO_CONTRACT_ID.to_string());
- }
- // DAO_DAOS_TABLE
- pub const DAO_DAOS_COL_BULLA: &str = "bulla";
- pub const DAO_DAOS_COL_NAME: &str = "name";
- pub const DAO_DAOS_COL_PARAMS: &str = "params";
- pub const DAO_DAOS_COL_LEAF_POSITION: &str = "leaf_position";
- pub const DAO_DAOS_COL_MINT_HEIGHT: &str = "mint_height";
- pub const DAO_DAOS_COL_TX_HASH: &str = "tx_hash";
- pub const DAO_DAOS_COL_CALL_INDEX: &str = "call_index";
- // DAO_PROPOSALS_TABLE
- pub const DAO_PROPOSALS_COL_BULLA: &str = "bulla";
- pub const DAO_PROPOSALS_COL_DAO_BULLA: &str = "dao_bulla";
- pub const DAO_PROPOSALS_COL_PROPOSAL: &str = "proposal";
- pub const DAO_PROPOSALS_COL_DATA: &str = "data";
- pub const DAO_PROPOSALS_COL_LEAF_POSITION: &str = "leaf_position";
- pub const DAO_PROPOSALS_COL_MONEY_SNAPSHOT_TREE: &str = "money_snapshot_tree";
- pub const DAO_PROPOSALS_COL_NULLIFIERS_SMT_SNAPSHOT: &str = "nullifiers_smt_snapshot";
- pub const DAO_PROPOSALS_COL_MINT_HEIGHT: &str = "mint_height";
- pub const DAO_PROPOSALS_COL_TX_HASH: &str = "tx_hash";
- pub const DAO_PROPOSALS_COL_CALL_INDEX: &str = "call_index";
- pub const DAO_PROPOSALS_COL_EXEC_HEIGHT: &str = "exec_height";
- pub const DAO_PROPOSALS_COL_EXEC_TX_HASH: &str = "exec_tx_hash";
- // DAO_VOTES_TABLE
- pub const DAO_VOTES_COL_PROPOSAL_BULLA: &str = "proposal_bulla";
- pub const DAO_VOTES_COL_VOTE_OPTION: &str = "vote_option";
- pub const DAO_VOTES_COL_YES_VOTE_BLIND: &str = "yes_vote_blind";
- pub const DAO_VOTES_COL_ALL_VOTE_VALUE: &str = "all_vote_value";
- pub const DAO_VOTES_COL_ALL_VOTE_BLIND: &str = "all_vote_blind";
- pub const DAO_VOTES_COL_BLOCK_HEIGHT: &str = "block_height";
- pub const DAO_VOTES_COL_TX_HASH: &str = "tx_hash";
- pub const DAO_VOTES_COL_CALL_INDEX: &str = "call_index";
- pub const DAO_VOTES_COL_NULLIFIERS: &str = "nullifiers";
- #[derive(Debug, Clone, SerialEncodable, SerialDecodable)]
- /// Parameters representing a DAO to be initialized
- pub struct DaoParams {
- /// The on chain representation of the DAO
- pub dao: Dao,
- /// DAO notes decryption secret key
- pub notes_secret_key: Option<SecretKey>,
- /// DAO proposals creator secret key
- pub proposer_secret_key: Option<SecretKey>,
- /// DAO proposals viewer secret key
- pub proposals_secret_key: Option<SecretKey>,
- /// DAO votes viewer secret key
- pub votes_secret_key: Option<SecretKey>,
- /// DAO proposals executor secret key
- pub exec_secret_key: Option<SecretKey>,
- /// DAO strongly supported proposals executor secret key
- pub early_exec_secret_key: Option<SecretKey>,
- }
- impl DaoParams {
- /// Generate new `DaoParams`. If a specific secret key is provided,
- /// the corresponding public key will be derived from it and ignore the provided one.
- #[allow(clippy::too_many_arguments)]
- pub fn new(
- proposer_limit: u64,
- quorum: u64,
- early_exec_quorum: u64,
- approval_ratio_base: u64,
- approval_ratio_quot: u64,
- gov_token_id: TokenId,
- notes_secret_key: Option<SecretKey>,
- notes_public_key: PublicKey,
- proposer_secret_key: Option<SecretKey>,
- proposer_public_key: PublicKey,
- proposals_secret_key: Option<SecretKey>,
- proposals_public_key: PublicKey,
- votes_secret_key: Option<SecretKey>,
- votes_public_key: PublicKey,
- exec_secret_key: Option<SecretKey>,
- exec_public_key: PublicKey,
- early_exec_secret_key: Option<SecretKey>,
- early_exec_public_key: PublicKey,
- bulla_blind: BaseBlind,
- ) -> Self {
- // Derive corresponding keys from their secret or use the provided ones.
- let notes_public_key = match notes_secret_key {
- Some(secret_key) => PublicKey::from_secret(secret_key),
- None => notes_public_key,
- };
- let proposer_public_key = match proposer_secret_key {
- Some(secret_key) => PublicKey::from_secret(secret_key),
- None => proposer_public_key,
- };
- let proposals_public_key = match proposals_secret_key {
- Some(secret_key) => PublicKey::from_secret(secret_key),
- None => proposals_public_key,
- };
- let votes_public_key = match votes_secret_key {
- Some(secret_key) => PublicKey::from_secret(secret_key),
- None => votes_public_key,
- };
- let exec_public_key = match exec_secret_key {
- Some(secret_key) => PublicKey::from_secret(secret_key),
- None => exec_public_key,
- };
- let early_exec_public_key = match early_exec_secret_key {
- Some(secret_key) => PublicKey::from_secret(secret_key),
- None => early_exec_public_key,
- };
- let dao = Dao {
- proposer_limit,
- quorum,
- early_exec_quorum,
- approval_ratio_base,
- approval_ratio_quot,
- gov_token_id,
- notes_public_key,
- proposer_public_key,
- proposals_public_key,
- votes_public_key,
- exec_public_key,
- early_exec_public_key,
- bulla_blind,
- };
- Self {
- dao,
- notes_secret_key,
- proposer_secret_key,
- proposals_secret_key,
- votes_secret_key,
- exec_secret_key,
- early_exec_secret_key,
- }
- }
- /// Parse provided toml string into `DaoParams`.
- /// If a specific secret key is provided, the corresponding public key
- /// will be derived from it and ignore the provided one.
- pub fn from_toml_str(toml: &str) -> Result<Self> {
- // Parse TOML file contents
- let Ok(contents) = toml::from_str::<toml::Value>(toml) else {
- return Err(Error::ParseFailed("Failed parsing TOML config"))
- };
- let Some(table) = contents.as_table() else {
- return Err(Error::ParseFailed("TOML not a map"))
- };
- // Grab configuration parameters
- let Some(proposer_limit) = table.get("proposer_limit") else {
- return Err(Error::ParseFailed("TOML does not contain proposer limit"))
- };
- let Some(proposer_limit) = proposer_limit.as_str() else {
- return Err(Error::ParseFailed("Invalid proposer limit: Not a string"))
- };
- if f64::from_str(proposer_limit).is_err() {
- return Err(Error::ParseFailed("Invalid proposer limit: Cannot be parsed to float"))
- }
- let proposer_limit = decode_base10(proposer_limit, BALANCE_BASE10_DECIMALS, true)?;
- let Some(quorum) = table.get("quorum") else {
- return Err(Error::ParseFailed("TOML does not contain quorum"))
- };
- let Some(quorum) = quorum.as_str() else {
- return Err(Error::ParseFailed("Invalid quorum: Not a string"))
- };
- if f64::from_str(quorum).is_err() {
- return Err(Error::ParseFailed("Invalid quorum: Cannot be parsed to float"))
- }
- let quorum = decode_base10(quorum, BALANCE_BASE10_DECIMALS, true)?;
- let Some(early_exec_quorum) = table.get("early_exec_quorum") else {
- return Err(Error::ParseFailed("TOML does not contain early exec quorum"))
- };
- let Some(early_exec_quorum) = early_exec_quorum.as_str() else {
- return Err(Error::ParseFailed("Invalid early exec quorum: Not a string"))
- };
- if f64::from_str(early_exec_quorum).is_err() {
- return Err(Error::ParseFailed("Invalid early exec quorum: Cannot be parsed to float"))
- }
- let early_exec_quorum = decode_base10(early_exec_quorum, BALANCE_BASE10_DECIMALS, true)?;
- let Some(approval_ratio) = table.get("approval_ratio") else {
- return Err(Error::ParseFailed("TOML does not contain approval ratio"))
- };
- let Some(approval_ratio) = approval_ratio.as_float() else {
- return Err(Error::ParseFailed("Invalid approval ratio: Not a float"))
- };
- if approval_ratio > 1.0 {
- return Err(Error::ParseFailed("Approval ratio cannot be >1.0"))
- }
- let approval_ratio_base = 100_u64;
- let approval_ratio_quot = (approval_ratio * approval_ratio_base as f64) as u64;
- let Some(gov_token_id) = table.get("gov_token_id") else {
- return Err(Error::ParseFailed("TOML does not contain gov token id"))
- };
- let Some(gov_token_id) = gov_token_id.as_str() else {
- return Err(Error::ParseFailed("Invalid gov token id: Not a string"))
- };
- let gov_token_id = TokenId::from_str(gov_token_id)?;
- let Some(bulla_blind) = table.get("bulla_blind") else {
- return Err(Error::ParseFailed("TOML does not contain bulla blind"))
- };
- let Some(bulla_blind) = bulla_blind.as_str() else {
- return Err(Error::ParseFailed("Invalid bulla blind: Not a string"))
- };
- let bulla_blind = BaseBlind::from_str(bulla_blind)?;
- // Grab DAO actions keypairs
- let notes_secret_key = match table.get("notes_secret_key") {
- Some(notes_secret_key) => {
- let Some(notes_secret_key) = notes_secret_key.as_str() else {
- return Err(Error::ParseFailed("Invalid notes secret key: Not a string"))
- };
- let Ok(notes_secret_key) = SecretKey::from_str(notes_secret_key) else {
- return Err(Error::ParseFailed("Invalid notes secret key: Decoding failed"))
- };
- Some(notes_secret_key)
- }
- None => None,
- };
- let notes_public_key = match notes_secret_key {
- Some(notes_secret_key) => PublicKey::from_secret(notes_secret_key),
- None => {
- let Some(notes_public_key) = table.get("notes_public_key") else {
- return Err(Error::ParseFailed("TOML does not contain notes public key"))
- };
- let Some(notes_public_key) = notes_public_key.as_str() else {
- return Err(Error::ParseFailed("Invalid notes public key: Not a string"))
- };
- let Ok(notes_public_key) = PublicKey::from_str(notes_public_key) else {
- return Err(Error::ParseFailed("Invalid notes public key: Decoding failed"))
- };
- notes_public_key
- }
- };
- let proposer_secret_key = match table.get("proposer_secret_key") {
- Some(proposer_secret_key) => {
- let Some(proposer_secret_key) = proposer_secret_key.as_str() else {
- return Err(Error::ParseFailed("Invalid proposer secret key: Not a string"))
- };
- let Ok(proposer_secret_key) = SecretKey::from_str(proposer_secret_key) else {
- return Err(Error::ParseFailed("Invalid proposer secret key: Decoding failed"))
- };
- Some(proposer_secret_key)
- }
- None => None,
- };
- let proposer_public_key = match proposer_secret_key {
- Some(proposer_secret_key) => PublicKey::from_secret(proposer_secret_key),
- None => {
- let Some(proposer_public_key) = table.get("proposer_public_key") else {
- return Err(Error::ParseFailed("TOML does not contain proposer public key"))
- };
- let Some(proposer_public_key) = proposer_public_key.as_str() else {
- return Err(Error::ParseFailed("Invalid proposer public key: Not a string"))
- };
- let Ok(proposer_public_key) = PublicKey::from_str(proposer_public_key) else {
- return Err(Error::ParseFailed("Invalid proposer public key: Decoding failed"))
- };
- proposer_public_key
- }
- };
- let proposals_secret_key = match table.get("proposals_secret_key") {
- Some(proposals_secret_key) => {
- let Some(proposals_secret_key) = proposals_secret_key.as_str() else {
- return Err(Error::ParseFailed("Invalid proposals secret key: Not a string"))
- };
- let Ok(proposals_secret_key) = SecretKey::from_str(proposals_secret_key) else {
- return Err(Error::ParseFailed("Invalid proposals secret key: Decoding failed"))
- };
- Some(proposals_secret_key)
- }
- None => None,
- };
- let proposals_public_key = match proposals_secret_key {
- Some(proposals_secret_key) => PublicKey::from_secret(proposals_secret_key),
- None => {
- let Some(proposals_public_key) = table.get("proposals_public_key") else {
- return Err(Error::ParseFailed("TOML does not contain proposals public key"))
- };
- let Some(proposals_public_key) = proposals_public_key.as_str() else {
- return Err(Error::ParseFailed("Invalid proposals public key: Not a string"))
- };
- let Ok(proposals_public_key) = PublicKey::from_str(proposals_public_key) else {
- return Err(Error::ParseFailed("Invalid proposals public key: Decoding failed"))
- };
- proposals_public_key
- }
- };
- let votes_secret_key = match table.get("votes_secret_key") {
- Some(votes_secret_key) => {
- let Some(votes_secret_key) = votes_secret_key.as_str() else {
- return Err(Error::ParseFailed("Invalid votes secret key: Not a string"))
- };
- let Ok(votes_secret_key) = SecretKey::from_str(votes_secret_key) else {
- return Err(Error::ParseFailed("Invalid votes secret key: Decoding failed"))
- };
- Some(votes_secret_key)
- }
- None => None,
- };
- let votes_public_key = match votes_secret_key {
- Some(votes_secret_key) => PublicKey::from_secret(votes_secret_key),
- None => {
- let Some(votes_public_key) = table.get("votes_public_key") else {
- return Err(Error::ParseFailed("TOML does not contain votes public key"))
- };
- let Some(votes_public_key) = votes_public_key.as_str() else {
- return Err(Error::ParseFailed("Invalid votes public key: Not a string"))
- };
- let Ok(votes_public_key) = PublicKey::from_str(votes_public_key) else {
- return Err(Error::ParseFailed("Invalid votes public key: Decoding failed"))
- };
- votes_public_key
- }
- };
- let exec_secret_key = match table.get("exec_secret_key") {
- Some(exec_secret_key) => {
- let Some(exec_secret_key) = exec_secret_key.as_str() else {
- return Err(Error::ParseFailed("Invalid exec secret key: Not a string"))
- };
- let Ok(exec_secret_key) = SecretKey::from_str(exec_secret_key) else {
- return Err(Error::ParseFailed("Invalid exec secret key: Decoding failed"))
- };
- Some(exec_secret_key)
- }
- None => None,
- };
- let exec_public_key = match exec_secret_key {
- Some(exec_secret_key) => PublicKey::from_secret(exec_secret_key),
- None => {
- let Some(exec_public_key) = table.get("exec_public_key") else {
- return Err(Error::ParseFailed("TOML does not contain exec public key"))
- };
- let Some(exec_public_key) = exec_public_key.as_str() else {
- return Err(Error::ParseFailed("Invalid exec public key: Not a string"))
- };
- let Ok(exec_public_key) = PublicKey::from_str(exec_public_key) else {
- return Err(Error::ParseFailed("Invalid exec public key: Decoding failed"))
- };
- exec_public_key
- }
- };
- let early_exec_secret_key = match table.get("early_exec_secret_key") {
- Some(early_exec_secret_key) => {
- let Some(early_exec_secret_key) = early_exec_secret_key.as_str() else {
- return Err(Error::ParseFailed("Invalid early exec secret key: Not a string"))
- };
- let Ok(early_exec_secret_key) = SecretKey::from_str(early_exec_secret_key) else {
- return Err(Error::ParseFailed("Invalid early exec secret key: Decoding failed"))
- };
- Some(early_exec_secret_key)
- }
- None => None,
- };
- let early_exec_public_key = match early_exec_secret_key {
- Some(early_exec_secret_key) => PublicKey::from_secret(early_exec_secret_key),
- None => {
- let Some(early_exec_public_key) = table.get("early_exec_public_key") else {
- return Err(Error::ParseFailed("TOML does not contain early exec public key"))
- };
- let Some(early_exec_public_key) = early_exec_public_key.as_str() else {
- return Err(Error::ParseFailed("Invalid early exec public key: Not a string"))
- };
- let Ok(early_exec_public_key) = PublicKey::from_str(early_exec_public_key) else {
- return Err(Error::ParseFailed("Invalid early exec public key: Decoding failed"))
- };
- early_exec_public_key
- }
- };
- Ok(Self::new(
- proposer_limit,
- quorum,
- early_exec_quorum,
- approval_ratio_base,
- approval_ratio_quot,
- gov_token_id,
- notes_secret_key,
- notes_public_key,
- proposer_secret_key,
- proposer_public_key,
- proposals_secret_key,
- proposals_public_key,
- votes_secret_key,
- votes_public_key,
- exec_secret_key,
- exec_public_key,
- early_exec_secret_key,
- early_exec_public_key,
- bulla_blind,
- ))
- }
- /// Generate a toml string containing the DAO configuration.
- pub fn toml_str(&self) -> String {
- // Header comments
- let mut toml = String::from(
- "## DAO configuration file\n\
- ##\n\
- ## Please make sure you go through all the settings so you can configure\n\
- ## your DAO properly.\n\
- ##\n\
- ## If you want to restrict access to certain actions, the corresponding\n\
- ## secret key can be omitted. All public keys, along with the DAO configuration\n\
- ## parameters must be shared.\n\
- ##\n\
- ## If you want to combine access to certain actions, you can use the same\n\
- ## secret and public key combination for them.\n\n",
- );
- // Configuration parameters
- toml += &format!(
- "## ====== DAO configuration parameters =====\n\n\
- ## The minimum amount of governance tokens needed to open a proposal for this DAO\n\
- proposer_limit = \"{}\"\n\n\
- ## Minimal threshold of participating total tokens needed for a proposal to pass\n\
- quorum = \"{}\"\n\n\
- ## Minimal threshold of participating total tokens needed for a proposal to\n\
- ## be considered strongly supported, enabling early execution.\n\
- ## Must be greater than or equal to normal quorum.\n\
- early_exec_quorum = \"{}\"\n\n\
- ## The ratio of yes votes/total votes needed for a proposal to pass (2 decimals)\n\
- approval_ratio = {}\n\n\
- ## DAO's governance token ID\n\
- gov_token_id = \"{}\"\n\n\
- ## Bulla blind\n\
- bulla_blind = \"{}\"\n\n",
- encode_base10(self.dao.proposer_limit, BALANCE_BASE10_DECIMALS),
- encode_base10(self.dao.quorum, BALANCE_BASE10_DECIMALS),
- encode_base10(self.dao.early_exec_quorum, BALANCE_BASE10_DECIMALS),
- self.dao.approval_ratio_quot as f64 / self.dao.approval_ratio_base as f64,
- self.dao.gov_token_id,
- self.dao.bulla_blind,
- );
- // DAO actions keypairs
- toml += &format!(
- "## ====== DAO actions keypairs =====\n\n\
- ## DAO notes decryption keypair\n\
- notes_public_key = \"{}\"\n",
- self.dao.notes_public_key,
- );
- match self.notes_secret_key {
- Some(secret_key) => toml += &format!("notes_secret_key = \"{secret_key}\"\n\n"),
- None => toml += "\n",
- }
- toml += &format!(
- "## DAO proposals creator keypair\n\
- proposer_public_key = \"{}\"\n",
- self.dao.proposer_public_key,
- );
- match self.proposer_secret_key {
- Some(secret_key) => toml += &format!("proposer_secret_key = \"{secret_key}\"\n\n"),
- None => toml += "\n",
- }
- toml += &format!(
- "## DAO proposals viewer keypair\n\
- proposals_public_key = \"{}\"\n",
- self.dao.proposals_public_key,
- );
- match self.proposals_secret_key {
- Some(secret_key) => toml += &format!("proposals_secret_key = \"{secret_key}\"\n\n"),
- None => toml += "\n",
- }
- toml += &format!(
- "## DAO votes viewer keypair\n\
- votes_public_key = \"{}\"\n",
- self.dao.votes_public_key,
- );
- match self.votes_secret_key {
- Some(secret_key) => toml += &format!("votes_secret_key = \"{secret_key}\"\n\n"),
- None => toml += "\n",
- }
- toml += &format!(
- "## DAO proposals executor keypair\n\
- exec_public_key = \"{}\"\n",
- self.dao.exec_public_key,
- );
- match self.exec_secret_key {
- Some(secret_key) => toml += &format!("exec_secret_key = \"{secret_key}\"\n\n"),
- None => toml += "\n",
- }
- toml += &format!(
- "## DAO strongly supported proposals executor keypair\n\
- early_exec_public_key = \"{}\"",
- self.dao.early_exec_public_key,
- );
- if let Some(secret_key) = self.early_exec_secret_key {
- toml += &format!("\nearly_exec_secret_key = \"{secret_key}\"")
- }
- toml
- }
- }
- impl fmt::Display for DaoParams {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- // Grab known secret keys
- let notes_secret_key = match self.notes_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let proposer_secret_key = match self.proposer_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let proposals_secret_key = match self.proposals_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let votes_secret_key = match self.votes_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let exec_secret_key = match self.exec_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let early_exec_secret_key = match self.early_exec_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let s = format!(
- "{}\n{}\n{}: {} ({})\n{}: {} ({})\n{}: {} ({})\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}",
- "DAO Parameters",
- "==============",
- "Proposer limit",
- encode_base10(self.dao.proposer_limit, BALANCE_BASE10_DECIMALS),
- self.dao.proposer_limit,
- "Quorum",
- encode_base10(self.dao.quorum, BALANCE_BASE10_DECIMALS),
- self.dao.quorum,
- "Early Exec Quorum",
- encode_base10(self.dao.early_exec_quorum, BALANCE_BASE10_DECIMALS),
- self.dao.early_exec_quorum,
- "Approval ratio",
- self.dao.approval_ratio_quot as f64 / self.dao.approval_ratio_base as f64,
- "Governance Token ID",
- self.dao.gov_token_id,
- "Notes Public key",
- self.dao.notes_public_key,
- "Notes Secret key",
- notes_secret_key,
- "Proposer Public key",
- self.dao.proposer_public_key,
- "Proposer Secret key",
- proposer_secret_key,
- "Proposals Public key",
- self.dao.proposals_public_key,
- "Proposals Secret key",
- proposals_secret_key,
- "Votes Public key",
- self.dao.votes_public_key,
- "Votes Secret key",
- votes_secret_key,
- "Exec Public key",
- self.dao.exec_public_key,
- "Exec Secret key",
- exec_secret_key,
- "Early Exec Public key",
- self.dao.early_exec_public_key,
- "Early Exec Secret key",
- early_exec_secret_key,
- "Bulla blind",
- self.dao.bulla_blind,
- );
- write!(f, "{s}")
- }
- }
- #[derive(Debug, Clone)]
- /// Structure representing a `DAO_DAOS_TABLE` record.
- pub struct DaoRecord {
- /// Name identifier for the DAO
- pub name: String,
- /// DAO parameters
- pub params: DaoParams,
- /// Leaf position of the DAO in the Merkle tree of DAOs
- pub leaf_position: Option<bridgetree::Position>,
- /// Block height of the transaction this DAO was deployed
- pub mint_height: Option<u32>,
- /// The transaction hash where the DAO was deployed
- pub tx_hash: Option<TransactionHash>,
- /// The call index in the transaction where the DAO was deployed
- pub call_index: Option<u8>,
- }
- impl DaoRecord {
- pub fn new(
- name: String,
- params: DaoParams,
- leaf_position: Option<bridgetree::Position>,
- mint_height: Option<u32>,
- tx_hash: Option<TransactionHash>,
- call_index: Option<u8>,
- ) -> Self {
- Self { name, params, leaf_position, mint_height, tx_hash, call_index }
- }
- pub fn bulla(&self) -> DaoBulla {
- self.params.dao.to_bulla()
- }
- }
- impl fmt::Display for DaoRecord {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- // Grab known secret keys
- let notes_secret_key = match self.params.notes_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let proposer_secret_key = match self.params.proposer_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let proposals_secret_key = match self.params.proposals_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let votes_secret_key = match self.params.votes_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let exec_secret_key = match self.params.exec_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- let early_exec_secret_key = match self.params.early_exec_secret_key {
- Some(secret_key) => format!("{secret_key}"),
- None => "None".to_string(),
- };
- // Grab mint information
- let leaf_position = match self.leaf_position {
- Some(p) => format!("{p:?}"),
- None => "None".to_string(),
- };
- let mint_height = match self.mint_height {
- Some(h) => format!("{h}"),
- None => "None".to_string(),
- };
- let tx_hash = match self.tx_hash {
- Some(t) => format!("{t}"),
- None => "None".to_string(),
- };
- let call_index = match self.call_index {
- Some(c) => format!("{c}"),
- None => "None".to_string(),
- };
- let s = format!(
- "{}\n{}\n{}: {}\n{}: {}\n{}: {} ({})\n{}: {} ({})\n{}: {} ({})\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}",
- "DAO Parameters",
- "==============",
- "Name",
- self.name,
- "Bulla",
- self.bulla(),
- "Proposer limit",
- encode_base10(self.params.dao.proposer_limit, BALANCE_BASE10_DECIMALS),
- self.params.dao.proposer_limit,
- "Quorum",
- encode_base10(self.params.dao.quorum, BALANCE_BASE10_DECIMALS),
- self.params.dao.quorum,
- "Early Exec Quorum",
- encode_base10(self.params.dao.early_exec_quorum, BALANCE_BASE10_DECIMALS),
- self.params.dao.early_exec_quorum,
- "Approval ratio",
- self.params.dao.approval_ratio_quot as f64 / self.params.dao.approval_ratio_base as f64,
- "Governance Token ID",
- self.params.dao.gov_token_id,
- "Notes Public key",
- self.params.dao.notes_public_key,
- "Notes Secret key",
- notes_secret_key,
- "Proposer Public key",
- self.params.dao.proposer_public_key,
- "Proposer Secret key",
- proposer_secret_key,
- "Proposals Public key",
- self.params.dao.proposals_public_key,
- "Proposals Secret key",
- proposals_secret_key,
- "Votes Public key",
- self.params.dao.votes_public_key,
- "Votes Secret key",
- votes_secret_key,
- "Exec Public key",
- self.params.dao.exec_public_key,
- "Exec Secret key",
- exec_secret_key,
- "Early Exec Public key",
- self.params.dao.early_exec_public_key,
- "Early Exec Secret key",
- early_exec_secret_key,
- "Bulla blind",
- self.params.dao.bulla_blind,
- "Leaf position",
- leaf_position,
- "Mint height",
- mint_height,
- "Transaction hash",
- tx_hash,
- "Call index",
- call_index,
- );
- write!(f, "{s}")
- }
- }
- #[derive(Debug, Clone, SerialEncodable, SerialDecodable)]
- /// Structure representing a `DAO_PROPOSALS_TABLE` record.
- pub struct ProposalRecord {
- /// The on chain representation of the proposal
- pub proposal: DaoProposal,
- /// Plaintext proposal call data the members share between them
- pub data: Option<Vec<u8>>,
- /// Leaf position of the proposal in the Merkle tree of proposals
- pub leaf_position: Option<bridgetree::Position>,
- /// Money merkle tree snapshot for reproducing the snapshot Merkle root
- pub money_snapshot_tree: Option<MerkleTree>,
- /// Money nullifiers SMT snapshot for reproducing the snapshot Merkle root
- pub nullifiers_smt_snapshot: Option<HashMap<BigUint, pallas::Base>>,
- /// Block height of the transaction this proposal was deployed
- pub mint_height: Option<u32>,
- /// The transaction hash where the proposal was deployed
- pub tx_hash: Option<TransactionHash>,
- /// The call index in the transaction where the proposal was deployed
- pub call_index: Option<u8>,
- /// Block height of the transaction this proposal was executed
- pub exec_height: Option<u32>,
- /// The transaction hash where the proposal was executed
- pub exec_tx_hash: Option<TransactionHash>,
- }
- impl ProposalRecord {
- pub fn bulla(&self) -> DaoProposalBulla {
- self.proposal.to_bulla()
- }
- }
- impl fmt::Display for ProposalRecord {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let leaf_position = match self.leaf_position {
- Some(p) => format!("{p:?}"),
- None => "None".to_string(),
- };
- let mint_height = match self.mint_height {
- Some(h) => format!("{h}"),
- None => "None".to_string(),
- };
- let tx_hash = match self.tx_hash {
- Some(t) => format!("{t}"),
- None => "None".to_string(),
- };
- let call_index = match self.call_index {
- Some(c) => format!("{c}"),
- None => "None".to_string(),
- };
- let s = format!(
- "{}\n{}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {}\n{}: {} ({})",
- "Proposal parameters",
- "===================",
- "Bulla",
- self.bulla(),
- "DAO Bulla",
- self.proposal.dao_bulla,
- "Proposal leaf position",
- leaf_position,
- "Proposal mint height",
- mint_height,
- "Proposal transaction hash",
- tx_hash,
- "Proposal call index",
- call_index,
- "Creation block window",
- self.proposal.creation_blockwindow,
- "Duration",
- self.proposal.duration_blockwindows,
- "Block windows"
- );
- write!(f, "{s}")
- }
- }
- #[derive(Debug, Clone)]
- /// Structure representing a `DAO_VOTES_TABLE` record.
- pub struct VoteRecord {
- /// Numeric identifier for the vote
- pub id: u64,
- /// Bulla identifier of the proposal this vote is for
- pub proposal: DaoProposalBulla,
- /// The vote
- pub vote_option: bool,
- /// Blinding factor for the yes vote
- pub yes_vote_blind: ScalarBlind,
- /// Value of all votes
- pub all_vote_value: u64,
- /// Blinding facfor of all votes
- pub all_vote_blind: ScalarBlind,
- /// Block height of the transaction this vote was casted
- pub block_height: u32,
- /// Transaction hash where this vote was casted
- pub tx_hash: TransactionHash,
- /// Call index in the transaction where this vote was casted
- pub call_index: u8,
- /// Vote input nullifiers
- pub nullifiers: Vec<Nullifier>,
- }
- impl Drk {
- /// Initialize wallet with tables for the DAO contract.
- pub async fn initialize_dao(&self) -> WalletDbResult<()> {
- // Initialize DAO wallet schema
- let wallet_schema = include_str!("../dao.sql");
- self.wallet.exec_batch_sql(wallet_schema)?;
- Ok(())
- }
- /// Fetch DAO Merkle trees from the wallet.
- /// If a tree doesn't exists a new Merkle Tree is returned.
- pub async fn get_dao_trees(&self) -> Result<(MerkleTree, MerkleTree)> {
- let daos_tree = match self.cache.merkle_trees.get(SLED_MERKLE_TREES_DAO_DAOS)? {
- Some(tree_bytes) => deserialize_async(&tree_bytes).await?,
- None => MerkleTree::new(u32::MAX as usize),
- };
- let proposals_tree = match self.cache.merkle_trees.get(SLED_MERKLE_TREES_DAO_PROPOSALS)? {
- Some(tree_bytes) => deserialize_async(&tree_bytes).await?,
- None => MerkleTree::new(u32::MAX as usize),
- };
- Ok((daos_tree, proposals_tree))
- }
- /// Auxiliary function to parse a `DAO_DAOS_TABLE` record.
- async fn parse_dao_record(&self, row: &[Value]) -> Result<DaoRecord> {
- let Value::Text(ref name) = row[1] else {
- return Err(Error::ParseFailed("[parse_dao_record] Name parsing failed"))
- };
- let name = name.clone();
- let Value::Blob(ref params_bytes) = row[2] else {
- return Err(Error::ParseFailed("[parse_dao_record] Params bytes parsing failed"))
- };
- let params = deserialize_async(params_bytes).await?;
- let leaf_position = match row[3] {
- Value::Blob(ref leaf_position_bytes) => {
- Some(deserialize_async(leaf_position_bytes).await?)
- }
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_record] Leaf position bytes parsing failed",
- ))
- }
- };
- let mint_height = match row[4] {
- Value::Integer(mint_height) => {
- let Ok(mint_height) = u32::try_from(mint_height) else {
- return Err(Error::ParseFailed("[parse_dao_record] Mint height parsing failed"))
- };
- Some(mint_height)
- }
- Value::Null => None,
- _ => return Err(Error::ParseFailed("[parse_dao_record] Mint height parsing failed")),
- };
- let tx_hash = match row[5] {
- Value::Blob(ref tx_hash_bytes) => Some(deserialize_async(tx_hash_bytes).await?),
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_record] Transaction hash bytes parsing failed",
- ))
- }
- };
- let call_index = match row[6] {
- Value::Integer(call_index) => {
- let Ok(call_index) = u8::try_from(call_index) else {
- return Err(Error::ParseFailed("[parse_dao_record] Call index parsing failed"))
- };
- Some(call_index)
- }
- Value::Null => None,
- _ => return Err(Error::ParseFailed("[parse_dao_record] Call index parsing failed")),
- };
- let dao = DaoRecord::new(name, params, leaf_position, mint_height, tx_hash, call_index);
- Ok(dao)
- }
- /// Fetch all known DAOs from the wallet.
- pub async fn get_daos(&self) -> Result<Vec<DaoRecord>> {
- let rows = match self.wallet.query_multiple(&DAO_DAOS_TABLE, &[], &[]) {
- Ok(r) => r,
- Err(e) => {
- return Err(Error::DatabaseError(format!("[get_daos] DAOs retrieval failed: {e}")))
- }
- };
- let mut daos = Vec::with_capacity(rows.len());
- for row in rows {
- daos.push(self.parse_dao_record(&row).await?);
- }
- Ok(daos)
- }
- /// Auxiliary function to parse a proposal record row.
- async fn parse_dao_proposal(&self, row: &[Value]) -> Result<ProposalRecord> {
- let Value::Blob(ref proposal_bytes) = row[2] else {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Proposal bytes bytes parsing failed",
- ))
- };
- let proposal = deserialize_async(proposal_bytes).await?;
- let data = match row[3] {
- Value::Blob(ref data_bytes) => Some(data_bytes.clone()),
- Value::Null => None,
- _ => return Err(Error::ParseFailed("[parse_dao_proposal] Data bytes parsing failed")),
- };
- let leaf_position = match row[4] {
- Value::Blob(ref leaf_position_bytes) => {
- Some(deserialize_async(leaf_position_bytes).await?)
- }
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Leaf position bytes parsing failed",
- ))
- }
- };
- let money_snapshot_tree = match row[5] {
- Value::Blob(ref money_snapshot_tree_bytes) => {
- Some(deserialize_async(money_snapshot_tree_bytes).await?)
- }
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Money snapshot tree bytes parsing failed",
- ))
- }
- };
- let nullifiers_smt_snapshot = match row[6] {
- Value::Blob(ref nullifiers_smt_snapshot_bytes) => {
- Some(deserialize_async(nullifiers_smt_snapshot_bytes).await?)
- }
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Nullifiers SMT snapshot bytes parsing failed",
- ))
- }
- };
- let mint_height = match row[7] {
- Value::Integer(mint_height) => {
- let Ok(mint_height) = u32::try_from(mint_height) else {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Mint height parsing failed",
- ))
- };
- Some(mint_height)
- }
- Value::Null => None,
- _ => return Err(Error::ParseFailed("[parse_dao_proposal] Mint height parsing failed")),
- };
- let tx_hash = match row[8] {
- Value::Blob(ref tx_hash_bytes) => Some(deserialize_async(tx_hash_bytes).await?),
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Transaction hash bytes parsing failed",
- ))
- }
- };
- let call_index = match row[9] {
- Value::Integer(call_index) => {
- let Ok(call_index) = u8::try_from(call_index) else {
- return Err(Error::ParseFailed("[parse_dao_proposal] Call index parsing failed"))
- };
- Some(call_index)
- }
- Value::Null => None,
- _ => return Err(Error::ParseFailed("[parse_dao_proposal] Call index parsing failed")),
- };
- let exec_height = match row[10] {
- Value::Integer(exec_height) => {
- let Ok(exec_height) = u32::try_from(exec_height) else {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Execution height parsing failed",
- ))
- };
- Some(exec_height)
- }
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Execution height parsing failed",
- ))
- }
- };
- let exec_tx_hash = match row[11] {
- Value::Blob(ref exec_tx_hash_bytes) => {
- Some(deserialize_async(exec_tx_hash_bytes).await?)
- }
- Value::Null => None,
- _ => {
- return Err(Error::ParseFailed(
- "[parse_dao_proposal] Execution transaction hash bytes parsing failed",
- ))
- }
- };
- Ok(ProposalRecord {
- proposal,
- data,
- leaf_position,
- money_snapshot_tree,
- nullifiers_smt_snapshot,
- mint_height,
- tx_hash,
- call_index,
- exec_height,
- exec_tx_hash,
- })
- }
- /// Fetch all known DAO proposals from the wallet given a DAO name.
- pub async fn get_dao_proposals(&self, name: &str) -> Result<Vec<ProposalRecord>> {
- let Ok(dao) = self.get_dao_by_name(name).await else {
- return Err(Error::DatabaseError(format!(
- "[get_dao_proposals] DAO with name {name} not found in wallet"
- )))
- };
- let rows = match self.wallet.query_multiple(
- &DAO_PROPOSALS_TABLE,
- &[],
- convert_named_params! {(DAO_PROPOSALS_COL_DAO_BULLA, serialize_async(&dao.bulla()).await)},
- ) {
- Ok(r) => r,
- Err(e) => {
- return Err(Error::DatabaseError(format!(
- "[get_dao_proposals] Proposals retrieval failed: {e}"
- )))
- }
- };
- let mut proposals = Vec::with_capacity(rows.len());
- for row in rows {
- let proposal = self.parse_dao_proposal(&row).await?;
- proposals.push(proposal);
- }
- Ok(proposals)
- }
- /// Auxiliary function to apply `DaoFunction::Mint` call data to
- /// the wallet and update the provided scan cache.
- /// Returns a flag indicating if the provided call refers to our
- /// own wallet.
- async fn apply_dao_mint_data(
- &self,
- scan_cache: &mut ScanCache,
- new_bulla: &DaoBulla,
- tx_hash: &TransactionHash,
- call_index: &u8,
- mint_height: &u32,
- ) -> Result<bool> {
- // Append the new dao bulla to the Merkle tree.
- // Every dao bulla has to be added.
- scan_cache.dao_daos_tree.append(MerkleNode::from(new_bulla.inner()));
- // Check if we have the DAO
- if !scan_cache.own_daos.contains_key(new_bulla) {
- return Ok(false)
- }
- // Confirm it
- scan_cache.log(format!(
- "[apply_dao_mint_data] Found minted DAO {new_bulla}, noting down for wallet update"
- ));
- if let Err(e) = self
- .confirm_dao(
- new_bulla,
- &scan_cache.dao_daos_tree.mark().unwrap(),
- tx_hash,
- call_index,
- mint_height,
- )
- .await
- {
- return Err(Error::DatabaseError(format!(
- "[apply_dao_mint_data] Confirm DAO failed: {e}"
- )))
- }
- Ok(true)
- }
- /// Auxiliary function to apply `DaoFunction::Propose` call data to
- /// the wallet and update the provided scan cache.
- /// Returns a flag indicating if the provided call refers to our
- /// own wallet.
- async fn apply_dao_propose_data(
- &self,
- scan_cache: &mut ScanCache,
- params: &DaoProposeParams,
- tx_hash: &TransactionHash,
- call_index: &u8,
- mint_height: &u32,
- ) -> Result<bool> {
- // Append the new proposal bulla to the Merkle tree.
- // Every proposal bulla has to be added.
- scan_cache.dao_proposals_tree.append(MerkleNode::from(params.proposal_bulla.inner()));
- // If we're able to decrypt this note, that's the way to link it
- // to a specific DAO.
- for (dao, (proposals_secret_key, _)) in &scan_cache.own_daos {
- // Check if we have the proposals key
- let Some(proposals_secret_key) = proposals_secret_key else { continue };
- // Try to decrypt the proposal note
- let Ok(note) = params.note.decrypt::<DaoProposal>(proposals_secret_key) else {
- continue
- };
- // We managed to decrypt it. Let's place this in a proper ProposalRecord object
- scan_cache.messages_buffer.push(format!(
- "[apply_dao_propose_data] Managed to decrypt proposal note for DAO: {dao}"
- ));
- // Check if we already got the record
- let our_proposal = if scan_cache.own_proposals.contains_key(¶ms.proposal_bulla) {
- // Grab the record from the db
- let mut our_proposal =
- self.get_dao_proposal_by_bulla(¶ms.proposal_bulla).await?;
- our_proposal.leaf_position = scan_cache.dao_proposals_tree.mark();
- our_proposal.money_snapshot_tree = Some(scan_cache.money_tree.clone());
- our_proposal.nullifiers_smt_snapshot = Some(scan_cache.money_smt.store.snapshot()?);
- our_proposal.mint_height = Some(*mint_height);
- our_proposal.tx_hash = Some(*tx_hash);
- our_proposal.call_index = Some(*call_index);
- our_proposal
- } else {
- let our_proposal = ProposalRecord {
- proposal: note,
- data: None,
- leaf_position: scan_cache.dao_proposals_tree.mark(),
- money_snapshot_tree: Some(scan_cache.money_tree.clone()),
- nullifiers_smt_snapshot: Some(scan_cache.money_smt.store.snapshot()?),
- mint_height: Some(*mint_height),
- tx_hash: Some(*tx_hash),
- call_index: Some(*call_index),
- exec_height: None,
- exec_tx_hash: None,
- };
- scan_cache.own_proposals.insert(params.proposal_bulla, *dao);
- our_proposal
- };
- // Update/store our record
- if let Err(e) = self.put_dao_proposal(&our_proposal).await {
- return Err(Error::DatabaseError(format!(
- "[apply_dao_propose_data] Put DAO proposals failed: {e}"
- )))
- }
- return Ok(true)
- }
- Ok(false)
- }
- /// Auxiliary function to apply `DaoFunction::Vote` call data to
- /// the wallet.
- /// Returns a flag indicating if the provided call refers to our
- /// own wallet.
- async fn apply_dao_vote_data(
- &self,
- scan_cache: &ScanCache,
- params: &DaoVoteParams,
- tx_hash: &TransactionHash,
- call_index: &u8,
- block_height: &u32,
- ) -> Result<bool> {
- // Check if we got the corresponding proposal
- let Some(dao_bulla) = scan_cache.own_proposals.get(¶ms.proposal_bulla) else {
- return Ok(false)
- };
- // Grab the proposal DAO votes key
- let Some((_, votes_secret_key)) = scan_cache.own_daos.get(dao_bulla) else {
- return Err(Error::DatabaseError(format!(
- "[apply_dao_vote_data] Couldn't find proposal {} DAO {}",
- params.proposal_bulla, dao_bulla,
- )))
- };
- // Check if we actually have the votes key
- let Some(votes_secret_key) = votes_secret_key else { return Ok(false) };
- // Decrypt the vote note
- let note = match params.note.decrypt_unsafe(votes_secret_key) {
- Ok(n) => n,
- Err(e) => {
- return Err(Error::DatabaseError(format!(
- "[apply_dao_vote_data] Couldn't decrypt proposal {} vote with DAO {} keys: {e}",
- params.proposal_bulla, dao_bulla,
- )))
- }
- };
- // Create the DAO vote record
- let vote_option = fp_to_u64(note[0]).unwrap();
- if vote_option > 1 {
- return Err(Error::DatabaseError(format!(
- "[apply_dao_vote_data] Malformed vote for proposal {}: {vote_option}",
- params.proposal_bulla,
- )))
- }
- let vote_option = vote_option != 0;
- let yes_vote_blind = Blind(fp_mod_fv(note[1]));
- let all_vote_value = fp_to_u64(note[2]).unwrap();
- let all_vote_blind = Blind(fp_mod_fv(note[3]));
- let v = VoteRecord {
- id: 0, // This will be set by SQLite AUTOINCREMENT
- proposal: params.proposal_bulla,
- vote_option,
- yes_vote_blind,
- all_vote_value,
- all_vote_blind,
- block_height: *block_height,
- tx_hash: *tx_hash,
- call_index: *call_index,
- nullifiers: params.inputs.iter().map(|i| i.vote_nullifier).collect(),
- };
- if let Err(e) = self.put_dao_vote(&v).await {
- return Err(Error::DatabaseError(format!(
- "[apply_dao_vote_data] Put DAO votes failed: {e}"
- )))
- }
- Ok(true)
- }
- /// Auxiliary function to apply `DaoFunction::Exec` call data to
- /// the wallet and update the provided scan cache.
- /// Returns a flag indicating if the provided call refers to our
- /// own wallet.
- async fn apply_dao_exec_data(
- &self,
- scan_cache: &ScanCache,
- params: &DaoExecParams,
- tx_hash: &TransactionHash,
- exec_height: &u32,
- ) -> Result<bool> {
- // Check if we got the corresponding proposal
- if !scan_cache.own_proposals.contains_key(¶ms.proposal_bulla) {
- return Ok(false)
- }
- // Grab proposal record key
- let key = serialize_async(¶ms.proposal_bulla).await;
- // Create an SQL `UPDATE` query to update proposal exec transaction hash
- let query = format!(
- "UPDATE {} SET {} = ?1, {} = ?2 WHERE {} = ?3;",
- *DAO_PROPOSALS_TABLE,
- DAO_PROPOSALS_COL_EXEC_HEIGHT,
- DAO_PROPOSALS_COL_EXEC_TX_HASH,
- DAO_PROPOSALS_COL_BULLA,
- );
- // Execute the query
- if let Err(e) = self
- .wallet
- .exec_sql(&query, rusqlite::params![Some(*exec_height), Some(serialize(tx_hash)), key])
- {
- return Err(Error::DatabaseError(format!(
- "[apply_dao_exec_data] Update DAO proposal failed: {e}"
- )))
- }
- Ok(true)
- }
- /// Append data related to DAO contract transactions into the
- /// wallet database and update the provided scan cache.
- /// Returns a flag indicating if provided data refer to our own
- /// wallet.
- pub async fn apply_tx_dao_data(
- &self,
- scan_cache: &mut ScanCache,
- data: &[u8],
- tx_hash: &TransactionHash,
- call_idx: &u8,
- block_height: &u32,
- ) -> Result<bool> {
- // Run through the transaction call data and see what we got:
- match DaoFunction::try_from(data[0])? {
- DaoFunction::Mint => {
- scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Mint call"));
- let params: DaoMintParams = deserialize_async(&data[1..]).await?;
- self.apply_dao_mint_data(
- scan_cache,
- ¶ms.dao_bulla,
- tx_hash,
- call_idx,
- block_height,
- )
- .await
- }
- DaoFunction::Propose => {
- scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Propose call"));
- let params: DaoProposeParams = deserialize_async(&data[1..]).await?;
- self.apply_dao_propose_data(scan_cache, ¶ms, tx_hash, call_idx, block_height)
- .await
- }
- DaoFunction::Vote => {
- scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Vote call"));
- let params: DaoVoteParams = deserialize_async(&data[1..]).await?;
- self.apply_dao_vote_data(scan_cache, ¶ms, tx_hash, call_idx, block_height).await
- }
- DaoFunction::Exec => {
- scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Exec call"));
- let params: DaoExecParams = deserialize_async(&data[1..]).await?;
- self.apply_dao_exec_data(scan_cache, ¶ms, tx_hash, block_height).await
- }
- DaoFunction::AuthMoneyTransfer => {
- scan_cache
- .log(String::from("[apply_tx_dao_data] Found Dao::AuthMoneyTransfer call"));
- // Does nothing, just verifies the other calls are correct
- Ok(false)
- }
- }
- }
- /// Confirm already imported DAO metadata into the wallet.
- /// Here we just write the leaf position, mint height, tx hash,
- /// and call index.
- pub async fn confirm_dao(
- &self,
- dao: &DaoBulla,
- leaf_position: &bridgetree::Position,
- tx_hash: &TransactionHash,
- call_index: &u8,
- mint_height: &u32,
- ) -> WalletDbResult<()> {
- // Grab dao record key
- let key = serialize_async(dao).await;
- // Create an SQL `UPDATE` query
- let query = format!(
- "UPDATE {} SET {} = ?1, {} = ?2, {} = ?3, {} = ?4 WHERE {} = ?5;",
- *DAO_DAOS_TABLE,
- DAO_DAOS_COL_LEAF_POSITION,
- DAO_DAOS_COL_MINT_HEIGHT,
- DAO_DAOS_COL_TX_HASH,
- DAO_DAOS_COL_CALL_INDEX,
- DAO_DAOS_COL_BULLA
- );
- // Create its params
- let params = rusqlite::params![
- serialize(leaf_position),
- Some(*mint_height),
- serialize(tx_hash),
- call_index,
- key,
- ];
- // Execute the query
- self.wallet.exec_sql(&query, params)
- }
- /// Import given DAO proposal into the wallet.
- pub async fn put_dao_proposal(&self, proposal: &ProposalRecord) -> Result<()> {
- // Check that we already have the proposal DAO
- if let Err(e) = self.get_dao_by_bulla(&proposal.proposal.dao_bulla).await {
- return Err(Error::DatabaseError(format!(
- "[put_dao_proposal] Couldn't find proposal {} DAO {}: {e}",
- proposal.bulla(),
- proposal.proposal.dao_bulla
- )))
- }
- // Grab proposal record key
- let key = serialize_async(&proposal.bulla()).await;
- // Create an SQL `INSERT OR REPLACE` query
- let query = format!(
- "INSERT OR REPLACE INTO {} ({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12);",
- *DAO_PROPOSALS_TABLE,
- DAO_PROPOSALS_COL_BULLA,
- DAO_PROPOSALS_COL_DAO_BULLA,
- DAO_PROPOSALS_COL_PROPOSAL,
- DAO_PROPOSALS_COL_DATA,
- DAO_PROPOSALS_COL_LEAF_POSITION,
- DAO_PROPOSALS_COL_MONEY_SNAPSHOT_TREE,
- DAO_PROPOSALS_COL_NULLIFIERS_SMT_SNAPSHOT,
- DAO_PROPOSALS_COL_MINT_HEIGHT,
- DAO_PROPOSALS_COL_TX_HASH,
- DAO_PROPOSALS_COL_CALL_INDEX,
- DAO_PROPOSALS_COL_EXEC_HEIGHT,
- DAO_PROPOSALS_COL_EXEC_TX_HASH,
- );
- // Create its params
- let data = match &proposal.data {
- Some(data) => Some(data),
- None => None,
- };
- let leaf_position = match &proposal.leaf_position {
- Some(leaf_position) => Some(serialize_async(leaf_position).await),
- None => None,
- };
- let money_snapshot_tree = match &proposal.money_snapshot_tree {
- Some(money_snapshot_tree) => Some(serialize_async(money_snapshot_tree).await),
- None => None,
- };
- let nullifiers_smt_snapshot = match &proposal.nullifiers_smt_snapshot {
- Some(nullifiers_smt_snapshot) => Some(serialize_async(nullifiers_smt_snapshot).await),
- None => None,
- };
- let tx_hash = match &proposal.tx_hash {
- Some(tx_hash) => Some(serialize_async(tx_hash).await),
- None => None,
- };
- let exec_tx_hash = match &proposal.exec_tx_hash {
- Some(exec_tx_hash) => Some(serialize_async(exec_tx_hash).await),
- None => None,
- };
- let params = rusqlite::params![
- key,
- serialize(&proposal.proposal.dao_bulla),
- serialize(&proposal.proposal),
- data,
- leaf_position,
- money_snapshot_tree,
- nullifiers_smt_snapshot,
- proposal.mint_height,
- tx_hash,
- proposal.call_index,
- proposal.exec_height,
- exec_tx_hash,
- ];
- // Execute the query
- if let Err(e) = self.wallet.exec_sql(&query, params) {
- return Err(Error::DatabaseError(format!(
- "[put_dao_proposal] Proposal insert failed: {e}"
- )))
- }
- Ok(())
- }
- /// Import given DAO vote into the wallet.
- pub async fn put_dao_vote(&self, vote: &VoteRecord) -> WalletDbResult<()> {
- // Create an SQL `INSERT OR REPLACE` query
- let query = format!(
- "INSERT INTO {} ({}, {}, {}, {}, {}, {}, {}, {}, {}) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9);",
- *DAO_VOTES_TABLE,
- DAO_VOTES_COL_PROPOSAL_BULLA,
- DAO_VOTES_COL_VOTE_OPTION,
- DAO_VOTES_COL_YES_VOTE_BLIND,
- DAO_VOTES_COL_ALL_VOTE_VALUE,
- DAO_VOTES_COL_ALL_VOTE_BLIND,
- DAO_VOTES_COL_BLOCK_HEIGHT,
- DAO_VOTES_COL_TX_HASH,
- DAO_VOTES_COL_CALL_INDEX,
- DAO_VOTES_COL_NULLIFIERS,
- );
- // Create its params
- let params = rusqlite::params![
- serialize(&vote.proposal),
- vote.vote_option as u64,
- serialize(&vote.yes_vote_blind),
- serialize(&vote.all_vote_value),
- serialize(&vote.all_vote_blind),
- vote.block_height,
- serialize(&vote.tx_hash),
- vote.call_index,
- serialize(&vote.nullifiers),
- ];
- // Execute the query
- self.wallet.exec_sql(&query, params)?;
- Ok(())
- }
- /// Reset the DAO Merkle trees in the cache.
- pub fn reset_dao_trees(&self, output: &mut Vec<String>) -> WalletDbResult<()> {
- output.push(String::from("Resetting DAO Merkle trees"));
- if let Err(e) = self.cache.merkle_trees.remove(SLED_MERKLE_TREES_DAO_DAOS) {
- output.push(format!("[reset_dao_trees] Resetting DAO DAOs Merkle tree failed: {e}"));
- return Err(WalletDbError::GenericError)
- }
- if let Err(e) = self.cache.merkle_trees.remove(SLED_MERKLE_TREES_DAO_PROPOSALS) {
- output
- .push(format!("[reset_dao_trees] Resetting DAO Proposals Merkle tree failed: {e}"));
- return Err(WalletDbError::GenericError)
- }
- output.push(String::from("Successfully reset DAO Merkle trees"));
- Ok(())
- }
- /// Reset confirmed DAOs in the wallet.
- pub fn reset_daos(&self, output: &mut Vec<String>) -> WalletDbResult<()> {
- output.push(String::from("Resetting DAO confirmations"));
- let query = format!(
- "UPDATE {} SET {} = NULL, {} = NULL, {} = NULL, {} = NULL;",
- *DAO_DAOS_TABLE,
- DAO_DAOS_COL_LEAF_POSITION,
- DAO_DAOS_COL_MINT_HEIGHT,
- DAO_DAOS_COL_TX_HASH,
- DAO_DAOS_COL_CALL_INDEX,
- );
- self.wallet.exec_sql(&query, &[])?;
- output.push(String::from("Successfully unconfirmed DAOs"));
- Ok(())
- }
- /// Reset confirmed DAOs in the wallet that were minted after
- /// provided height.
- pub fn unconfirm_daos_after(
- &self,
- height: &u32,
- output: &mut Vec<String>,
- ) -> WalletDbResult<()> {
- output.push(format!("Resetting DAO confirmations after: {height}"));
- let query = format!(
- "UPDATE {} SET {} = NULL, {} = NULL, {} = NULL, {} = NULL WHERE {} > ?1;",
- *DAO_DAOS_TABLE,
- DAO_DAOS_COL_LEAF_POSITION,
- DAO_DAOS_COL_MINT_HEIGHT,
- DAO_DAOS_COL_TX_HASH,
- DAO_DAOS_COL_CALL_INDEX,
- DAO_DAOS_COL_MINT_HEIGHT,
- );
- self.wallet.exec_sql(&query, rusqlite::params![Some(*height)])?;
- output.push(String::from("Successfully unconfirmed DAOs"));
- Ok(())
- }
- /// Reset all DAO proposals in the wallet.
- pub fn reset_dao_proposals(&self, output: &mut Vec<String>) -> WalletDbResult<()> {
- output.push(String::from("Resetting DAO proposals confirmations"));
- let query = format!(
- "UPDATE {} SET {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL;",
- *DAO_PROPOSALS_TABLE,
- DAO_PROPOSALS_COL_LEAF_POSITION,
- DAO_PROPOSALS_COL_MONEY_SNAPSHOT_TREE,
- DAO_PROPOSALS_COL_NULLIFIERS_SMT_SNAPSHOT,
- DAO_PROPOSALS_COL_MINT_HEIGHT,
- DAO_PROPOSALS_COL_TX_HASH,
- DAO_PROPOSALS_COL_CALL_INDEX,
- DAO_PROPOSALS_COL_EXEC_HEIGHT,
- DAO_PROPOSALS_COL_EXEC_TX_HASH,
- );
- self.wallet.exec_sql(&query, &[])?;
- output.push(String::from("Successfully unconfirmed DAO proposals"));
- Ok(())
- }
- /// Reset DAO proposals in the wallet that were minted after
- /// provided height.
- pub fn unconfirm_dao_proposals_after(
- &self,
- height: &u32,
- output: &mut Vec<String>,
- ) -> WalletDbResult<()> {
- output.push(format!("Resetting DAO proposals confirmations after: {height}"));
- let query = format!(
- "UPDATE {} SET {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL, {} = NULL WHERE {} > ?1;",
- *DAO_PROPOSALS_TABLE,
- DAO_PROPOSALS_COL_LEAF_POSITION,
- DAO_PROPOSALS_COL_MONEY_SNAPSHOT_TREE,
- DAO_PROPOSALS_COL_NULLIFIERS_SMT_SNAPSHOT,
- DAO_PROPOSALS_COL_MINT_HEIGHT,
- DAO_PROPOSALS_COL_TX_HASH,
- DAO_PROPOSALS_COL_CALL_INDEX,
- DAO_PROPOSALS_COL_EXEC_HEIGHT,
- DAO_PROPOSALS_COL_EXEC_TX_HASH,
- DAO_PROPOSALS_COL_MINT_HEIGHT,
- );
- self.wallet.exec_sql(&query, rusqlite::params![Some(*height)])?;
- output.push(String::from("Successfully unconfirmed DAO proposals"));
- Ok(())
- }
- /// Reset execution information in the wallet for DAO proposals
- /// that were executed after provided height.
- pub fn unexec_dao_proposals_after(
- &self,
- height: &u32,
- output: &mut Vec<String>,
- ) -> WalletDbResult<()> {
- output.push(format!("Resetting DAO proposals execution information after: {height}"));
- let query = format!(
- "UPDATE {} SET {} = NULL, {} = NULL WHERE {} > ?1;",
- *DAO_PROPOSALS_TABLE,
- DAO_PROPOSALS_COL_EXEC_HEIGHT,
- DAO_PROPOSALS_COL_EXEC_TX_HASH,
- DAO_PROPOSALS_COL_EXEC_HEIGHT,
- );
- self.wallet.exec_sql(&query, rusqlite::params![Some(*height)])?;
- output.push(String::from("Successfully reset DAO proposals execution information"));
- Ok(())
- }
- /// Reset all DAO votes in the wallet.
- pub fn reset_dao_votes(&self, output: &mut Vec<String>) -> WalletDbResult<()> {
- output.push(String::from("Resetting DAO votes"));
- let query = format!("DELETE FROM {};", *DAO_VOTES_TABLE);
- self.wallet.exec_sql(&query, &[])?;
- output.push(String::from("Successfully reset DAO votes"));
- Ok(())
- }
- /// Remove the DAO votes in the wallet that were created after
- /// provided height.
- pub fn remove_dao_votes_after(
- &self,
- height: &u32,
- output: &mut Vec<String>,
- ) -> WalletDbResult<()> {
- output.push(format!("Removing DAO votes after: {height}"));
- let query =
- format!("DELETE FROM {} WHERE {} > ?1;", *DAO_VOTES_TABLE, DAO_VOTES_COL_BLOCK_HEIGHT);
- self.wallet.exec_sql(&query, rusqlite::params![height])?;
- output.push(String::from("Successfully removed DAO votes"));
- Ok(())
- }
- /// Import given DAO params into the wallet with a given name.
- pub async fn import_dao(
- &self,
- name: &str,
- params: &DaoParams,
- output: &mut Vec<String>,
- ) -> Result<()> {
- // Grab the params DAO
- let bulla = params.dao.to_bulla();
- // Check if we already have imported the DAO so we retain its
- // mint information.
- if let Ok(dao) = self.get_dao_by_bulla(&bulla).await {
- output.push(format!("Updating \"{}\" DAO keys and name into the wallet", dao.name));
- let query = format!(
- "UPDATE {} SET {} = ?1, {} = ?2 WHERE {} = ?3;",
- *DAO_DAOS_TABLE, DAO_DAOS_COL_NAME, DAO_DAOS_COL_PARAMS, DAO_DAOS_COL_BULLA
- );
- if let Err(e) = self.wallet.exec_sql(
- &query,
- rusqlite::params![
- name,
- serialize_async(params).await,
- serialize_async(&bulla).await
- ],
- ) {
- return Err(Error::DatabaseError(format!("[import_dao] DAO update failed: {e}")))
- };
- return Ok(())
- }
- // Import the new DAO
- output.push(format!("Importing \"{name}\" DAO into the wallet"));
- let query = format!(
- "INSERT INTO {} ({}, {}, {}) VALUES (?1, ?2, ?3);",
- *DAO_DAOS_TABLE, DAO_DAOS_COL_BULLA, DAO_DAOS_COL_NAME, DAO_DAOS_COL_PARAMS
- );
- if let Err(e) = self.wallet.exec_sql(
- &query,
- rusqlite::params![
- serialize_async(¶ms.dao.to_bulla()).await,
- name,
- serialize_async(params).await
- ],
- ) {
- return Err(Error::DatabaseError(format!("[import_dao] DAO insert failed: {e}")))
- };
- Ok(())
- }
- /// Remove a DAO and all its records given its name.
- pub async fn remove_dao(&self, name: &str, output: &mut Vec<String>) -> Result<()> {
- output.push(format!("Removing \"{name}\" DAO from the wallet"));
- let query = format!("DELETE FROM {} WHERE {} = ?1;", *DAO_DAOS_TABLE, DAO_DAOS_COL_NAME);
- if let Err(e) = self.wallet.exec_sql(&query, rusqlite::params![name]) {
- return Err(Error::DatabaseError(format!("[remove_dao] DAO removal failed: {e}")))
- };
- output.push(String::from("Successfully removed DAO"));
- Ok(())
- }
- /// Fetch a DAO given its bulla.
- pub async fn get_dao_by_bulla(&self, bulla: &DaoBulla) -> Result<DaoRecord> {
- let row = match self.wallet.query_single(
- &DAO_DAOS_TABLE,
- &[],
- convert_named_params! {(DAO_DAOS_COL_BULLA, serialize_async(bulla).await)},
- ) {
- Ok(r) => r,
- Err(e) => {
- return Err(Error::DatabaseError(format!(
- "[get_dao_by_bulla] DAO retrieval failed: {e}"
- )))
- }
- };
- self.parse_dao_record(&row).await
- }
- /// Fetch a DAO given its name.
- pub async fn get_dao_by_name(&self, name: &str) -> Result<DaoRecord> {
- let row = match self.wallet.query_single(
- &DAO_DAOS_TABLE,
- &[],
- convert_named_params! {(DAO_DAOS_COL_NAME, name)},
- ) {
- Ok(r) => r,
- Err(e) => {
- return Err(Error::DatabaseError(format!(
- "[get_dao_by_name] DAO retrieval failed: {e}"
- )))
- }
- };
- self.parse_dao_record(&row).await
- }
- /// List DAO(s) imported in the wallet. If a name is given, just print the
- /// metadata for that specific one, if found.
- pub async fn dao_list(&self, name: &Option<String>, output: &mut Vec<String>) -> Result<()> {
- if let Some(name) = name {
- let dao = self.get_dao_by_name(name).await?;
- output.push(format!("{dao}"));
- let address: Address =
- StandardAddress::from_public(self.network, dao.params.dao.notes_public_key).into();
- output.push(format!("Wallet Address: {address}"));
- return Ok(());
- }
- let daos = self.get_daos().await?;
- for (i, dao) in daos.iter().enumerate() {
- output.push(format!("{i}. {}", dao.name));
- }
- Ok(())
- }
- /// Fetch known unspent balances from the wallet for the given DAO name.
- pub async fn dao_balance(&self, name: &str) -> Result<HashMap<String, u64>> {
- let dao = self.get_dao_by_name(name).await?;
- 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_spend_hook);
- coins.retain(|x| x.0.note.user_data == dao.bulla().inner());
- // Fill this map with balances
- let mut balmap: HashMap<String, u64> = HashMap::new();
- for coin in coins {
- let mut value = coin.0.note.value;
- if let Some(prev) = balmap.get(&coin.0.note.token_id.to_string()) {
- value += prev;
- }
- balmap.insert(coin.0.note.token_id.to_string(), value);
- }
- Ok(balmap)
- }
- /// Fetch known unspent balances from the wallet for the given DAO name.
- pub async fn dao_mining_config(&self, name: &str, output: &mut Vec<String>) -> Result<()> {
- let dao = self.get_dao_by_name(name).await?;
- let address: Address =
- StandardAddress::from_public(self.network, dao.params.dao.notes_public_key).into();
- let recipient = address.to_string();
- let spend_hook = format!(
- "{}",
- FuncRef { contract_id: *DAO_CONTRACT_ID, func_code: DaoFunction::Exec as u8 }
- .to_func_id()
- );
- let user_data = bs58::encode(dao.bulla().inner().to_repr()).into_string();
- output.push(String::from("DarkFi DAO mining configuration address:"));
- output.push(
- base64::encode(&serialize(&(recipient, Some(spend_hook), Some(user_data)))).to_string(),
- );
- Ok(())
- }
- /// Fetch all known DAO proposalss from the wallet.
- pub async fn get_proposals(&self) -> Result<Vec<ProposalRecord>> {
- let rows = match self.wallet.query_multiple(&DAO_PROPOSALS_TABLE, &[], &[]) {
- Ok(r) => r,
- Err(e) => {
- return Err(Error::DatabaseError(format!(
- "[get_proposals] DAO proposalss retrieval failed: {e}"
- )))
- }
- };
- let mut daos = Vec::with_capacity(rows.len());
- for row in rows {
- daos.push(self.parse_dao_proposal(&row).await?);
- }
- Ok(daos)
- }
- /// Fetch a DAO proposal by its bulla.
- pub async fn get_dao_proposal_by_bulla(
- &self,
- bulla: &DaoProposalBulla,
- ) -> Result<ProposalRecord> {
- // Grab the proposal record
- let row = match self.wallet.query_single(
- &DAO_PROPOSALS_TABLE,
- &[],
- convert_named_params! {(DAO_PROPOSALS_COL_BULLA, serialize_async(bulla).await)},
- ) {
- Ok(r) => r,
- Err(e) => {
- return Err(Error::DatabaseError(format!(
- "[get_dao_proposal_by_bulla] DAO proposal retrieval failed: {e}"
- )))
- }
- };
- // Parse rest of the record
- self.parse_dao_proposal(&row).await
- }
- // Fetch all known DAO proposal votes from the wallet given a proposal ID.
- pub async fn get_dao_proposal_votes(
- &self,
- proposal: &DaoProposalBulla,
- ) -> Result<Vec<VoteRecord>> {
- let rows = match self.wallet.query_multiple(
- &DAO_VOTES_TABLE,
- &[],
- convert_named_params! {(DAO_VOTES_COL_PROPOSAL_BULLA, serialize_async(proposal).await)},
- ) {
- Ok(r) => r,
- Err(e) => {
- return Err(Error::DatabaseError(format!(
- "[get_dao_proposal_votes] Votes retrieval failed: {e}"
- )))
- }
- };
- let mut votes = Vec::with_capacity(rows.len());
- for row in rows {
- let Value::Integer(id) = row[0] else {
- return Err(Error::ParseFailed("[get_dao_proposal_votes] ID parsing failed"))
- };
- let Ok(id) = u64::try_from(id) else {
- return Err(Error::ParseFailed("[get_dao_proposal_votes] ID parsing failed"))
- };
- let Value::Blob(ref proposal_bytes) = row[1] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Proposal bytes bytes parsing failed",
- ))
- };
- let proposal = deserialize_async(proposal_bytes).await?;
- let Value::Integer(vote_option) = row[2] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Vote option parsing failed",
- ))
- };
- let Ok(vote_option) = u32::try_from(vote_option) else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Vote option parsing failed",
- ))
- };
- let vote_option = vote_option != 0;
- let Value::Blob(ref yes_vote_blind_bytes) = row[3] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Yes vote blind bytes parsing failed",
- ))
- };
- let yes_vote_blind = deserialize_async(yes_vote_blind_bytes).await?;
- let Value::Blob(ref all_vote_value_bytes) = row[4] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] All vote value bytes parsing failed",
- ))
- };
- let all_vote_value = deserialize_async(all_vote_value_bytes).await?;
- let Value::Blob(ref all_vote_blind_bytes) = row[5] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] All vote blind bytes parsing failed",
- ))
- };
- let all_vote_blind = deserialize_async(all_vote_blind_bytes).await?;
- let Value::Integer(block_height) = row[6] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Block height parsing failed",
- ))
- };
- let Ok(block_height) = u32::try_from(block_height) else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Block height parsing failed",
- ))
- };
- let Value::Blob(ref tx_hash_bytes) = row[7] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Transaction hash bytes parsing failed",
- ))
- };
- let tx_hash = deserialize_async(tx_hash_bytes).await?;
- let Value::Integer(call_index) = row[8] else {
- return Err(Error::ParseFailed("[get_dao_proposal_votes] Call index parsing failed"))
- };
- let Ok(call_index) = u8::try_from(call_index) else {
- return Err(Error::ParseFailed("[get_dao_proposal_votes] Call index parsing failed"))
- };
- let Value::Blob(ref nullifiers_bytes) = row[9] else {
- return Err(Error::ParseFailed(
- "[get_dao_proposal_votes] Nullifiers bytes parsing failed",
- ))
- };
- let nullifiers = deserialize_async(nullifiers_bytes).await?;
- let vote = VoteRecord {
- id,
- proposal,
- vote_option,
- yes_vote_blind,
- all_vote_value,
- all_vote_blind,
- block_height,
- tx_hash,
- call_index,
- nullifiers,
- };
- votes.push(vote);
- }
- Ok(votes)
- }
- /// Mint a DAO on-chain.
- pub async fn dao_mint(&self, name: &str) -> Result<Transaction> {
- // Retrieve the dao record
- let dao = self.get_dao_by_name(name).await?;
- // Check its not already minted
- if dao.tx_hash.is_some() {
- return Err(Error::Custom(
- "[dao_mint] This DAO seems to have already been minted on-chain".to_string(),
- ))
- }
- // Check that we have all the keys
- if dao.params.notes_secret_key.is_none() ||
- dao.params.proposer_secret_key.is_none() ||
- dao.params.proposals_secret_key.is_none() ||
- dao.params.votes_secret_key.is_none() ||
- dao.params.exec_secret_key.is_none() ||
- dao.params.early_exec_secret_key.is_none()
- {
- return Err(Error::Custom(
- "[dao_mint] We need all the secrets key to mint the DAO on-chain".to_string(),
- ))
- }
- // Now we need to do a lookup for the zkas proof bincodes, and create
- // the circuit objects and proving keys so we can build the transaction.
- // We also do this through the RPC. First we grab the fee call from money.
- let zkas_bins = self.lookup_zkas(&MONEY_CONTRACT_ID).await?;
- let Some(fee_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_FEE_NS_V1)
- else {
- return Err(Error::Custom("Fee circuit not found".to_string()))
- };
- let fee_zkbin = ZkBinary::decode(&fee_zkbin.1, false)?;
- let fee_circuit = ZkCircuit::new(empty_witnesses(&fee_zkbin)?, &fee_zkbin);
- // Creating Fee circuit proving key
- let fee_pk = ProvingKey::build(fee_zkbin.k, &fee_circuit);
- // Now we grab the DAO mint
- let zkas_bins = self.lookup_zkas(&DAO_CONTRACT_ID).await?;
- let Some(dao_mint_zkbin) = zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_MINT_NS)
- else {
- return Err(Error::DatabaseError("[dao_mint] DAO Mint circuit not found".to_string()))
- };
- let dao_mint_zkbin = ZkBinary::decode(&dao_mint_zkbin.1, false)?;
- let dao_mint_circuit = ZkCircuit::new(empty_witnesses(&dao_mint_zkbin)?, &dao_mint_zkbin);
- // Creating DAO Mint circuit proving key
- let dao_mint_pk = ProvingKey::build(dao_mint_zkbin.k, &dao_mint_circuit);
- // Create the DAO mint call
- let notes_secret_key = dao.params.notes_secret_key.unwrap();
- let (params, proofs) = make_mint_call(
- &dao.params.dao,
- ¬es_secret_key,
- &dao.params.proposer_secret_key.unwrap(),
- &dao.params.proposals_secret_key.unwrap(),
- &dao.params.votes_secret_key.unwrap(),
- &dao.params.exec_secret_key.unwrap(),
- &dao.params.early_exec_secret_key.unwrap(),
- &dao_mint_zkbin,
- &dao_mint_pk,
- )?;
- let mut data = vec![DaoFunction::Mint as u8];
- params.encode_async(&mut data).await?;
- let call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
- // Create the TransactionBuilder containing above call
- let mut tx_builder = TransactionBuilder::new(ContractCallLeaf { call, proofs }, vec![])?;
- // We first have to execute the fee-less tx to gather its used gas, and then we feed
- // it into the fee-creating function.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&[notes_secret_key])?;
- tx.signatures.push(sigs);
- let tree = self.get_money_tree().await?;
- let (fee_call, fee_proofs, fee_secrets) =
- self.append_fee_call(&tx, &tree, &fee_pk, &fee_zkbin, None).await?;
- // Append the fee call to the transaction
- tx_builder.append(ContractCallLeaf { call: fee_call, proofs: fee_proofs }, vec![])?;
- // Now build the actual transaction and sign it with all necessary keys.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&[notes_secret_key])?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&fee_secrets)?;
- tx.signatures.push(sigs);
- Ok(tx)
- }
- /// Create a DAO transfer proposal.
- #[allow(clippy::too_many_arguments)]
- pub async fn dao_propose_transfer(
- &self,
- name: &str,
- duration_blockwindows: u64,
- amount: &str,
- token_id: TokenId,
- recipient: PublicKey,
- spend_hook: Option<FuncId>,
- user_data: Option<pallas::Base>,
- ) -> Result<ProposalRecord> {
- // Fetch DAO and check its deployed
- let dao = self.get_dao_by_name(name).await?;
- if dao.leaf_position.is_none() || dao.tx_hash.is_none() || dao.call_index.is_none() {
- return Err(Error::Custom(
- "[dao_propose_transfer] DAO seems to not have been deployed yet".to_string(),
- ))
- }
- // Check that we have the proposer key
- if dao.params.proposer_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_propose_transfer] We need the proposer secret key to create proposals for this DAO".to_string(),
- ))
- }
- // Fetch DAO unspent OwnCoins to see what its balance is
- let dao_spend_hook =
- FuncRef { contract_id: *DAO_CONTRACT_ID, func_code: DaoFunction::Exec as u8 }
- .to_func_id();
- let dao_bulla = dao.bulla();
- let dao_owncoins =
- self.get_contract_token_coins(&token_id, &dao_spend_hook, &dao_bulla.inner()).await?;
- if dao_owncoins.is_empty() {
- return Err(Error::Custom(format!(
- "[dao_propose_transfer] Did not find any {token_id} unspent coins owned by this DAO"
- )))
- }
- // Check DAO balance is sufficient
- let amount = decode_base10(amount, BALANCE_BASE10_DECIMALS, false)?;
- if dao_owncoins.iter().map(|x| x.note.value).sum::<u64>() < amount {
- return Err(Error::Custom(format!(
- "[dao_propose_transfer] Not enough DAO balance for token ID: {token_id}",
- )))
- }
- // Generate proposal coin attributes
- let proposal_coinattrs = CoinAttributes {
- public_key: recipient,
- value: amount,
- token_id,
- spend_hook: spend_hook.unwrap_or(FuncId::none()),
- user_data: user_data.unwrap_or(pallas::Base::ZERO),
- blind: Blind::random(&mut OsRng),
- };
- // Convert coin_params to actual coins
- let proposal_coins = vec![proposal_coinattrs.to_coin()];
- let mut proposal_data = vec![];
- proposal_coins.encode_async(&mut proposal_data).await?;
- // Create Auth calls
- let auth_calls = vec![
- DaoAuthCall {
- contract_id: *DAO_CONTRACT_ID,
- function_code: DaoFunction::AuthMoneyTransfer as u8,
- auth_data: proposal_data,
- },
- DaoAuthCall {
- contract_id: *MONEY_CONTRACT_ID,
- function_code: MoneyFunction::TransferV1 as u8,
- auth_data: vec![],
- },
- ];
- // Retrieve next block height and current block time target,
- // to compute their window.
- let next_block_height = self.get_next_block_height().await?;
- let block_target = self.get_block_target().await?;
- let creation_blockwindow = blockwindow(next_block_height, block_target);
- // Create the actual proposal
- let proposal = DaoProposal {
- auth_calls,
- creation_blockwindow,
- duration_blockwindows,
- user_data: user_data.unwrap_or(pallas::Base::ZERO),
- dao_bulla,
- blind: Blind::random(&mut OsRng),
- };
- let proposal_record = ProposalRecord {
- proposal,
- data: Some(serialize_async(&proposal_coinattrs).await),
- leaf_position: None,
- money_snapshot_tree: None,
- nullifiers_smt_snapshot: None,
- mint_height: None,
- tx_hash: None,
- call_index: None,
- exec_height: None,
- exec_tx_hash: None,
- };
- if let Err(e) = self.put_dao_proposal(&proposal_record).await {
- return Err(Error::DatabaseError(format!(
- "[dao_propose_transfer] Put DAO proposal failed: {e}"
- )))
- }
- Ok(proposal_record)
- }
- /// Create a DAO generic proposal.
- pub async fn dao_propose_generic(
- &self,
- name: &str,
- duration_blockwindows: u64,
- user_data: Option<pallas::Base>,
- ) -> Result<ProposalRecord> {
- // Fetch DAO and check its deployed
- let dao = self.get_dao_by_name(name).await?;
- if dao.leaf_position.is_none() || dao.tx_hash.is_none() || dao.call_index.is_none() {
- return Err(Error::Custom(
- "[dao_propose_generic] DAO seems to not have been deployed yet".to_string(),
- ))
- }
- // Check that we have the proposer key
- if dao.params.proposer_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_propose_generic] We need the proposer secret key to create proposals for this DAO".to_string(),
- ))
- }
- // Retrieve next block height and current block time target,
- // to compute their window.
- let next_block_height = self.get_next_block_height().await?;
- let block_target = self.get_block_target().await?;
- let creation_blockwindow = blockwindow(next_block_height, block_target);
- // Create the actual proposal
- let proposal = DaoProposal {
- auth_calls: vec![],
- creation_blockwindow,
- duration_blockwindows,
- user_data: user_data.unwrap_or(pallas::Base::ZERO),
- dao_bulla: dao.bulla(),
- blind: Blind::random(&mut OsRng),
- };
- let proposal_record = ProposalRecord {
- proposal,
- data: None,
- leaf_position: None,
- money_snapshot_tree: None,
- nullifiers_smt_snapshot: None,
- mint_height: None,
- tx_hash: None,
- call_index: None,
- exec_height: None,
- exec_tx_hash: None,
- };
- if let Err(e) = self.put_dao_proposal(&proposal_record).await {
- return Err(Error::DatabaseError(format!(
- "[dao_propose_generic] Put DAO proposal failed: {e}"
- )))
- }
- Ok(proposal_record)
- }
- /// Create a DAO transfer proposal transaction.
- pub async fn dao_transfer_proposal_tx(&self, proposal: &ProposalRecord) -> Result<Transaction> {
- // Check we know the plaintext data
- if proposal.data.is_none() {
- return Err(Error::Custom(
- "[dao_transfer_proposal_tx] Proposal plainext data is empty".to_string(),
- ))
- }
- let proposal_coinattrs: CoinAttributes =
- deserialize_async(proposal.data.as_ref().unwrap()).await?;
- // Fetch DAO and check its deployed
- let Ok(dao) = self.get_dao_by_bulla(&proposal.proposal.dao_bulla).await else {
- return Err(Error::Custom(format!(
- "[dao_transfer_proposal_tx] DAO {} was not found",
- proposal.proposal.dao_bulla
- )))
- };
- if dao.leaf_position.is_none() || dao.tx_hash.is_none() || dao.call_index.is_none() {
- return Err(Error::Custom(
- "[dao_transfer_proposal_tx] DAO seems to not have been deployed yet".to_string(),
- ))
- }
- // Check that we have the proposer key
- if dao.params.proposer_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_transfer_proposal_tx] We need the proposer secret key to create proposals for this DAO".to_string(),
- ))
- }
- // Fetch DAO unspent OwnCoins to see what its balance is for the coin
- let dao_spend_hook =
- FuncRef { contract_id: *DAO_CONTRACT_ID, func_code: DaoFunction::Exec as u8 }
- .to_func_id();
- let dao_owncoins = self
- .get_contract_token_coins(
- &proposal_coinattrs.token_id,
- &dao_spend_hook,
- &proposal.proposal.dao_bulla.inner(),
- )
- .await?;
- if dao_owncoins.is_empty() {
- return Err(Error::Custom(format!(
- "[dao_transfer_proposal_tx] Did not find any {} unspent coins owned by this DAO",
- proposal_coinattrs.token_id,
- )))
- }
- // Check DAO balance is sufficient
- if dao_owncoins.iter().map(|x| x.note.value).sum::<u64>() < proposal_coinattrs.value {
- return Err(Error::Custom(format!(
- "[dao_transfer_proposal_tx] Not enough DAO balance for token ID: {}",
- proposal_coinattrs.token_id,
- )))
- }
- // Fetch our own governance OwnCoins to see what our balance is
- let gov_owncoins = self.get_token_coins(&dao.params.dao.gov_token_id).await?;
- if gov_owncoins.is_empty() {
- return Err(Error::Custom(format!(
- "[dao_transfer_proposal_tx] Did not find any governance {} coins in wallet",
- dao.params.dao.gov_token_id
- )))
- }
- // Find which governance coins we can use
- let mut total_value = 0;
- let mut gov_owncoins_to_use = vec![];
- for gov_owncoin in gov_owncoins {
- if total_value >= dao.params.dao.proposer_limit {
- break
- }
- total_value += gov_owncoin.note.value;
- gov_owncoins_to_use.push(gov_owncoin);
- }
- // Check our governance coins balance is sufficient
- if total_value < dao.params.dao.proposer_limit {
- return Err(Error::Custom(format!(
- "[dao_transfer_proposal_tx] Not enough gov token {} balance to propose",
- dao.params.dao.gov_token_id
- )))
- }
- // Now we need to do a lookup for the zkas proof bincodes, and create
- // the circuit objects and proving keys so we can build the transaction.
- // We also do this through the RPC. First we grab the fee call from money.
- let zkas_bins = self.lookup_zkas(&MONEY_CONTRACT_ID).await?;
- let Some(fee_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_FEE_NS_V1)
- else {
- return Err(Error::Custom(
- "[dao_transfer_proposal_tx] Fee circuit not found".to_string(),
- ))
- };
- let fee_zkbin = ZkBinary::decode(&fee_zkbin.1, false)?;
- let fee_circuit = ZkCircuit::new(empty_witnesses(&fee_zkbin)?, &fee_zkbin);
- // Creating Fee circuit proving key
- let fee_pk = ProvingKey::build(fee_zkbin.k, &fee_circuit);
- // Now we grab the DAO bins
- let zkas_bins = self.lookup_zkas(&DAO_CONTRACT_ID).await?;
- let Some(propose_burn_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_PROPOSE_INPUT_NS)
- else {
- return Err(Error::Custom(
- "[dao_transfer_proposal_tx] Propose Burn circuit not found".to_string(),
- ))
- };
- let Some(propose_main_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_PROPOSE_MAIN_NS)
- else {
- return Err(Error::Custom(
- "[dao_transfer_proposal_tx] Propose Main circuit not found".to_string(),
- ))
- };
- let propose_burn_zkbin = ZkBinary::decode(&propose_burn_zkbin.1, false)?;
- let propose_main_zkbin = ZkBinary::decode(&propose_main_zkbin.1, false)?;
- let propose_burn_circuit =
- ZkCircuit::new(empty_witnesses(&propose_burn_zkbin)?, &propose_burn_zkbin);
- let propose_main_circuit =
- ZkCircuit::new(empty_witnesses(&propose_main_zkbin)?, &propose_main_zkbin);
- // Creating DAO ProposeBurn and ProposeMain circuits proving keys
- let propose_burn_pk = ProvingKey::build(propose_burn_zkbin.k, &propose_burn_circuit);
- let propose_main_pk = ProvingKey::build(propose_main_zkbin.k, &propose_main_circuit);
- // Fetch our money Merkle tree
- let money_merkle_tree = self.get_money_tree().await?;
- // Now we can create the proposal transaction parameters.
- // We first generate the `DaoProposeStakeInput` inputs,
- // using our governance OwnCoins.
- let mut inputs = Vec::with_capacity(gov_owncoins_to_use.len());
- for gov_owncoin in gov_owncoins_to_use {
- let input = DaoProposeStakeInput {
- secret: gov_owncoin.secret,
- note: gov_owncoin.note.clone(),
- leaf_position: gov_owncoin.leaf_position,
- merkle_path: money_merkle_tree.witness(gov_owncoin.leaf_position, 0).unwrap(),
- };
- inputs.push(input);
- }
- // Now create the parameters for the proposal tx.
- // Fetch the daos Merkle tree to compute the DAO Merkle path and root.
- let (daos_tree, _) = self.get_dao_trees().await?;
- let (dao_merkle_path, dao_merkle_root) = {
- let root = daos_tree.root(0).unwrap();
- let leaf_pos = dao.leaf_position.unwrap();
- let dao_merkle_path = daos_tree.witness(leaf_pos, 0).unwrap();
- (dao_merkle_path, root)
- };
- // Generate the Money nullifiers Sparse Merkle Tree
- let store = CacheSmtStorage::new(CacheOverlay::new(&self.cache)?, SLED_MONEY_SMT_TREE);
- let money_null_smt = CacheSmt::new(store, PoseidonFp::new(), &EMPTY_NODES_FP);
- // Create the proposal call
- let call = DaoProposeCall {
- money_null_smt: &money_null_smt,
- inputs,
- proposal: proposal.proposal.clone(),
- dao: dao.params.dao,
- dao_leaf_position: dao.leaf_position.unwrap(),
- dao_merkle_path,
- dao_merkle_root,
- };
- let (params, proofs, signature_secrets) = call.make(
- &dao.params.proposer_secret_key.unwrap(),
- &propose_burn_zkbin,
- &propose_burn_pk,
- &propose_main_zkbin,
- &propose_main_pk,
- )?;
- // Encode the call
- let mut data = vec![DaoFunction::Propose as u8];
- params.encode_async(&mut data).await?;
- let call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
- // Create the TransactionBuilder containing above call
- let mut tx_builder = TransactionBuilder::new(ContractCallLeaf { call, proofs }, vec![])?;
- // We first have to execute the fee-less tx to gather its used gas, and then we feed
- // it into the fee-creating function.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&signature_secrets)?;
- tx.signatures.push(sigs);
- let tree = self.get_money_tree().await?;
- let (fee_call, fee_proofs, fee_secrets) =
- self.append_fee_call(&tx, &tree, &fee_pk, &fee_zkbin, None).await?;
- // Append the fee call to the transaction
- tx_builder.append(ContractCallLeaf { call: fee_call, proofs: fee_proofs }, vec![])?;
- // Now build the actual transaction and sign it with all necessary keys.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&signature_secrets)?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&fee_secrets)?;
- tx.signatures.push(sigs);
- Ok(tx)
- }
- /// Create a DAO generic proposal transaction.
- pub async fn dao_generic_proposal_tx(&self, proposal: &ProposalRecord) -> Result<Transaction> {
- // Fetch DAO and check its deployed
- let Ok(dao) = self.get_dao_by_bulla(&proposal.proposal.dao_bulla).await else {
- return Err(Error::Custom(format!(
- "[dao_generic_proposal_tx] DAO {} was not found",
- proposal.proposal.dao_bulla
- )))
- };
- if dao.leaf_position.is_none() || dao.tx_hash.is_none() || dao.call_index.is_none() {
- return Err(Error::Custom(
- "[dao_generic_proposal_tx] DAO seems to not have been deployed yet".to_string(),
- ))
- }
- // Check that we have the proposer key
- if dao.params.proposer_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_generic_proposal_tx] We need the proposer secret key to create proposals for this DAO".to_string(),
- ))
- }
- // Fetch our own governance OwnCoins to see what our balance is
- let gov_owncoins = self.get_token_coins(&dao.params.dao.gov_token_id).await?;
- if gov_owncoins.is_empty() {
- return Err(Error::Custom(format!(
- "[dao_generic_proposal_tx] Did not find any governance {} coins in wallet",
- dao.params.dao.gov_token_id
- )))
- }
- // Find which governance coins we can use
- let mut total_value = 0;
- let mut gov_owncoins_to_use = vec![];
- for gov_owncoin in gov_owncoins {
- if total_value >= dao.params.dao.proposer_limit {
- break
- }
- total_value += gov_owncoin.note.value;
- gov_owncoins_to_use.push(gov_owncoin);
- }
- // Check our governance coins balance is sufficient
- if total_value < dao.params.dao.proposer_limit {
- return Err(Error::Custom(format!(
- "[dao_generic_proposal_tx] Not enough gov token {} balance to propose",
- dao.params.dao.gov_token_id
- )))
- }
- // Now we need to do a lookup for the zkas proof bincodes, and create
- // the circuit objects and proving keys so we can build the transaction.
- // We also do this through the RPC. First we grab the fee call from money.
- let zkas_bins = self.lookup_zkas(&MONEY_CONTRACT_ID).await?;
- let Some(fee_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_FEE_NS_V1)
- else {
- return Err(Error::Custom("[dao_generic_proposal_tx] Fee circuit not found".to_string()))
- };
- let fee_zkbin = ZkBinary::decode(&fee_zkbin.1, false)?;
- let fee_circuit = ZkCircuit::new(empty_witnesses(&fee_zkbin)?, &fee_zkbin);
- // Creating Fee circuit proving key
- let fee_pk = ProvingKey::build(fee_zkbin.k, &fee_circuit);
- // Now we grab the DAO bins
- let zkas_bins = self.lookup_zkas(&DAO_CONTRACT_ID).await?;
- let Some(propose_burn_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_PROPOSE_INPUT_NS)
- else {
- return Err(Error::Custom(
- "[dao_generic_proposal_tx] Propose Burn circuit not found".to_string(),
- ))
- };
- let Some(propose_main_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_PROPOSE_MAIN_NS)
- else {
- return Err(Error::Custom(
- "[dao_generic_proposal_tx] Propose Main circuit not found".to_string(),
- ))
- };
- let propose_burn_zkbin = ZkBinary::decode(&propose_burn_zkbin.1, false)?;
- let propose_main_zkbin = ZkBinary::decode(&propose_main_zkbin.1, false)?;
- let propose_burn_circuit =
- ZkCircuit::new(empty_witnesses(&propose_burn_zkbin)?, &propose_burn_zkbin);
- let propose_main_circuit =
- ZkCircuit::new(empty_witnesses(&propose_main_zkbin)?, &propose_main_zkbin);
- // Creating DAO ProposeBurn and ProposeMain circuits proving keys
- let propose_burn_pk = ProvingKey::build(propose_burn_zkbin.k, &propose_burn_circuit);
- let propose_main_pk = ProvingKey::build(propose_main_zkbin.k, &propose_main_circuit);
- // Fetch our money Merkle tree
- let money_merkle_tree = self.get_money_tree().await?;
- // Now we can create the proposal transaction parameters.
- // We first generate the `DaoProposeStakeInput` inputs,
- // using our governance OwnCoins.
- let mut inputs = Vec::with_capacity(gov_owncoins_to_use.len());
- for gov_owncoin in gov_owncoins_to_use {
- let input = DaoProposeStakeInput {
- secret: gov_owncoin.secret,
- note: gov_owncoin.note.clone(),
- leaf_position: gov_owncoin.leaf_position,
- merkle_path: money_merkle_tree.witness(gov_owncoin.leaf_position, 0).unwrap(),
- };
- inputs.push(input);
- }
- // Now create the parameters for the proposal tx.
- // Fetch the daos Merkle tree to compute the DAO Merkle path and root.
- let (daos_tree, _) = self.get_dao_trees().await?;
- let (dao_merkle_path, dao_merkle_root) = {
- let root = daos_tree.root(0).unwrap();
- let leaf_pos = dao.leaf_position.unwrap();
- let dao_merkle_path = daos_tree.witness(leaf_pos, 0).unwrap();
- (dao_merkle_path, root)
- };
- // Generate the Money nullifiers Sparse Merkle Tree
- let store = CacheSmtStorage::new(CacheOverlay::new(&self.cache)?, SLED_MONEY_SMT_TREE);
- let money_null_smt = CacheSmt::new(store, PoseidonFp::new(), &EMPTY_NODES_FP);
- // Create the proposal call
- let call = DaoProposeCall {
- money_null_smt: &money_null_smt,
- inputs,
- proposal: proposal.proposal.clone(),
- dao: dao.params.dao,
- dao_leaf_position: dao.leaf_position.unwrap(),
- dao_merkle_path,
- dao_merkle_root,
- };
- let (params, proofs, signature_secrets) = call.make(
- &dao.params.proposer_secret_key.unwrap(),
- &propose_burn_zkbin,
- &propose_burn_pk,
- &propose_main_zkbin,
- &propose_main_pk,
- )?;
- // Encode the call
- let mut data = vec![DaoFunction::Propose as u8];
- params.encode_async(&mut data).await?;
- let call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
- // Create the TransactionBuilder containing above call
- let mut tx_builder = TransactionBuilder::new(ContractCallLeaf { call, proofs }, vec![])?;
- // We first have to execute the fee-less tx to gather its used gas, and then we feed
- // it into the fee-creating function.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&signature_secrets)?;
- tx.signatures.push(sigs);
- let tree = self.get_money_tree().await?;
- let (fee_call, fee_proofs, fee_secrets) =
- self.append_fee_call(&tx, &tree, &fee_pk, &fee_zkbin, None).await?;
- // Append the fee call to the transaction
- tx_builder.append(ContractCallLeaf { call: fee_call, proofs: fee_proofs }, vec![])?;
- // Now build the actual transaction and sign it with all necessary keys.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&signature_secrets)?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&fee_secrets)?;
- tx.signatures.push(sigs);
- Ok(tx)
- }
- /// Vote on a DAO proposal
- pub async fn dao_vote(
- &self,
- proposal_bulla: &DaoProposalBulla,
- vote_option: bool,
- weight: Option<u64>,
- ) -> Result<Transaction> {
- // Feth the proposal and check its deployed
- let Ok(proposal) = self.get_dao_proposal_by_bulla(proposal_bulla).await else {
- return Err(Error::Custom(format!("[dao_vote] Proposal {proposal_bulla} was not found")))
- };
- if proposal.leaf_position.is_none() ||
- proposal.money_snapshot_tree.is_none() ||
- proposal.nullifiers_smt_snapshot.is_none() ||
- proposal.tx_hash.is_none() ||
- proposal.call_index.is_none()
- {
- return Err(Error::Custom(
- "[dao_vote] Proposal seems to not have been deployed yet".to_string(),
- ))
- }
- // Check proposal is not executed
- if let Some(exec_tx_hash) = proposal.exec_tx_hash {
- return Err(Error::Custom(format!(
- "[dao_vote] Proposal was executed on transaction: {exec_tx_hash}"
- )))
- }
- // Fetch DAO and check its deployed
- let Ok(dao) = self.get_dao_by_bulla(&proposal.proposal.dao_bulla).await else {
- return Err(Error::Custom(format!(
- "[dao_vote] DAO {} was not found",
- proposal.proposal.dao_bulla
- )))
- };
- if dao.leaf_position.is_none() || dao.tx_hash.is_none() || dao.call_index.is_none() {
- return Err(Error::Custom(
- "[dao_vote] DAO seems to not have been deployed yet".to_string(),
- ))
- }
- // Fetch all the proposal votes to check for duplicate nullifiers
- let votes = self.get_dao_proposal_votes(proposal_bulla).await?;
- let mut votes_nullifiers = vec![];
- for vote in votes {
- for nullifier in vote.nullifiers {
- if !votes_nullifiers.contains(&nullifier) {
- votes_nullifiers.push(nullifier);
- }
- }
- }
- // Fetch our own governance OwnCoins to see what our balance is
- let gov_owncoins = self.get_token_coins(&dao.params.dao.gov_token_id).await?;
- if gov_owncoins.is_empty() {
- return Err(Error::Custom(format!(
- "[dao_vote] Did not find any governance {} coins in wallet",
- dao.params.dao.gov_token_id
- )))
- }
- // Find which governance coins we can use
- let gov_owncoins_to_use = match weight {
- Some(_weight) => {
- // TODO: Build a proper coin selection algorithm so that we can use a
- // coins combination that matches the requested weight
- return Err(Error::Custom(
- "[dao_vote] Fractional vote weight not supported yet".to_string(),
- ))
- }
- // If no weight was specified, use them all
- None => gov_owncoins,
- };
- // Now we need to do a lookup for the zkas proof bincodes, and create
- // the circuit objects and proving keys so we can build the transaction.
- // We also do this through the RPC. First we grab the fee call from money.
- let zkas_bins = self.lookup_zkas(&MONEY_CONTRACT_ID).await?;
- let Some(fee_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_FEE_NS_V1)
- else {
- return Err(Error::Custom("[dao_vote] Fee circuit not found".to_string()))
- };
- let fee_zkbin = ZkBinary::decode(&fee_zkbin.1, false)?;
- let fee_circuit = ZkCircuit::new(empty_witnesses(&fee_zkbin)?, &fee_zkbin);
- // Creating Fee circuit proving key
- let fee_pk = ProvingKey::build(fee_zkbin.k, &fee_circuit);
- // Now we grab the DAO bins
- let zkas_bins = self.lookup_zkas(&DAO_CONTRACT_ID).await?;
- let Some(dao_vote_burn_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_VOTE_INPUT_NS)
- else {
- return Err(Error::Custom("[dao_vote] DAO Vote Burn circuit not found".to_string()))
- };
- let Some(dao_vote_main_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_VOTE_MAIN_NS)
- else {
- return Err(Error::Custom("[dao_vote] DAO Vote Main circuit not found".to_string()))
- };
- let dao_vote_burn_zkbin = ZkBinary::decode(&dao_vote_burn_zkbin.1, false)?;
- let dao_vote_main_zkbin = ZkBinary::decode(&dao_vote_main_zkbin.1, false)?;
- let dao_vote_burn_circuit =
- ZkCircuit::new(empty_witnesses(&dao_vote_burn_zkbin)?, &dao_vote_burn_zkbin);
- let dao_vote_main_circuit =
- ZkCircuit::new(empty_witnesses(&dao_vote_main_zkbin)?, &dao_vote_main_zkbin);
- // Creating DAO VoteBurn and VoteMain circuits proving keys
- let dao_vote_burn_pk = ProvingKey::build(dao_vote_burn_zkbin.k, &dao_vote_burn_circuit);
- let dao_vote_main_pk = ProvingKey::build(dao_vote_main_zkbin.k, &dao_vote_main_circuit);
- // Now create the parameters for the vote tx
- let mut inputs = Vec::with_capacity(gov_owncoins_to_use.len());
- for gov_owncoin in gov_owncoins_to_use {
- // Skip governance coins that are not part of the snapshot
- let Ok(merkle_path) = proposal
- .money_snapshot_tree
- .as_ref()
- .unwrap()
- .witness(gov_owncoin.leaf_position, 0)
- else {
- continue
- };
- let nullifier = poseidon_hash([gov_owncoin.secret.inner(), gov_owncoin.coin.inner()]);
- let vote_nullifier =
- poseidon_hash([nullifier, gov_owncoin.secret.inner(), proposal_bulla.inner()]);
- if votes_nullifiers.contains(&vote_nullifier.into()) {
- return Err(Error::Custom("[dao_vote] Duplicate input nullifier found".to_string()))
- };
- let input = DaoVoteInput {
- secret: gov_owncoin.secret,
- note: gov_owncoin.note.clone(),
- leaf_position: gov_owncoin.leaf_position,
- merkle_path,
- };
- inputs.push(input);
- }
- if inputs.is_empty() {
- return Err(Error::Custom(format!(
- "[dao_vote] Did not find any governance {} coins in wallet before proposal snapshot",
- dao.params.dao.gov_token_id
- )))
- }
- // Retrieve next block height and current block time target,
- // to compute their window.
- let next_block_height = self.get_next_block_height().await?;
- let block_target = self.get_block_target().await?;
- let current_blockwindow = blockwindow(next_block_height, block_target);
- // Check if proposal has expired
- if current_blockwindow >=
- proposal.proposal.creation_blockwindow + proposal.proposal.duration_blockwindows
- {
- return Err(Error::Custom("[dao_vote] Proposal has expired".to_string()))
- }
- // Generate the Money nullifiers Sparse Merkle Tree
- let store = MemoryStorageFp { tree: proposal.nullifiers_smt_snapshot.unwrap() };
- let money_null_smt = SmtMemoryFp::new(store, PoseidonFp::new(), &EMPTY_NODES_FP);
- // Create the vote call
- let call = DaoVoteCall {
- money_null_smt: &money_null_smt,
- inputs,
- vote_option,
- proposal: proposal.proposal.clone(),
- dao: dao.params.dao.clone(),
- current_blockwindow,
- };
- let (params, proofs, signature_secrets) = call.make(
- &dao_vote_burn_zkbin,
- &dao_vote_burn_pk,
- &dao_vote_main_zkbin,
- &dao_vote_main_pk,
- )?;
- // Encode the call
- let mut data = vec![DaoFunction::Vote as u8];
- params.encode_async(&mut data).await?;
- let call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
- // Create the TransactionBuilder containing above call
- let mut tx_builder = TransactionBuilder::new(ContractCallLeaf { call, proofs }, vec![])?;
- // We first have to execute the fee-less tx to gather its used gas, and then we feed
- // it into the fee-creating function.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&signature_secrets)?;
- tx.signatures.push(sigs);
- let tree = self.get_money_tree().await?;
- let (fee_call, fee_proofs, fee_secrets) =
- self.append_fee_call(&tx, &tree, &fee_pk, &fee_zkbin, None).await?;
- // Append the fee call to the transaction
- tx_builder.append(ContractCallLeaf { call: fee_call, proofs: fee_proofs }, vec![])?;
- // Now build the actual transaction and sign it with all necessary keys.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&signature_secrets)?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&fee_secrets)?;
- tx.signatures.push(sigs);
- Ok(tx)
- }
- /// Execute a DAO transfer proposal.
- pub async fn dao_exec_transfer(
- &self,
- proposal: &ProposalRecord,
- early: bool,
- ) -> Result<Transaction> {
- if proposal.leaf_position.is_none() ||
- proposal.money_snapshot_tree.is_none() ||
- proposal.nullifiers_smt_snapshot.is_none() ||
- proposal.tx_hash.is_none() ||
- proposal.call_index.is_none()
- {
- return Err(Error::Custom(
- "[dao_exec_transfer] Proposal seems to not have been deployed yet".to_string(),
- ))
- }
- // Check proposal is not executed
- if let Some(exec_tx_hash) = proposal.exec_tx_hash {
- return Err(Error::Custom(format!(
- "[dao_exec_transfer] Proposal was executed on transaction: {exec_tx_hash}"
- )))
- }
- // Check we know the plaintext data and they are valid
- if proposal.data.is_none() {
- return Err(Error::Custom(
- "[dao_exec_transfer] Proposal plainext data is empty".to_string(),
- ))
- }
- let proposal_coinattrs: CoinAttributes =
- deserialize_async(proposal.data.as_ref().unwrap()).await?;
- // Fetch DAO and check its deployed
- let Ok(dao) = self.get_dao_by_bulla(&proposal.proposal.dao_bulla).await else {
- return Err(Error::Custom(format!(
- "[dao_exec_transfer] DAO {} was not found",
- proposal.proposal.dao_bulla
- )))
- };
- if dao.leaf_position.is_none() || dao.tx_hash.is_none() || dao.call_index.is_none() {
- return Err(Error::Custom(
- "[dao_exec_transfer] DAO seems to not have been deployed yet".to_string(),
- ))
- }
- // Check that we have the exec key
- if dao.params.exec_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_exec_transfer] We need the exec secret key to execute proposals for this DAO"
- .to_string(),
- ))
- }
- // If early flag is provided, check that we have the early exec key
- if early && dao.params.early_exec_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_exec_transfer] We need the early exec secret key to execute proposals early for this DAO"
- .to_string(),
- ))
- }
- // Check proposal is approved
- let votes = self.get_dao_proposal_votes(&proposal.bulla()).await?;
- let mut yes_vote_value = 0;
- let mut yes_vote_blind = Blind::ZERO;
- let mut all_vote_value = 0;
- let mut all_vote_blind = Blind::ZERO;
- for vote in votes {
- if vote.vote_option {
- yes_vote_value += vote.all_vote_value;
- };
- yes_vote_blind += vote.yes_vote_blind;
- all_vote_value += vote.all_vote_value;
- all_vote_blind += vote.all_vote_blind;
- }
- let approval_ratio = (yes_vote_value as f64 * 100.0) / all_vote_value as f64;
- let dao_approval_ratio =
- (dao.params.dao.approval_ratio_quot / dao.params.dao.approval_ratio_base) as f64;
- if approval_ratio < dao_approval_ratio {
- return Err(Error::Custom(
- "[dao_exec_transfer] Proposal is not approved yet".to_string(),
- ))
- }
- // Check the quorum has been met
- if all_vote_value < dao.params.dao.quorum {
- return Err(Error::Custom(
- "[dao_exec_transfer] DAO quorum is not reached yet".to_string(),
- ))
- }
- if early && all_vote_value < dao.params.dao.early_exec_quorum {
- return Err(Error::Custom(
- "[dao_exec_transfer] DAO early execution quorum is not reached yet".to_string(),
- ))
- }
- // Fetch DAO unspent OwnCoins to see what its balance is for the coin
- let dao_spend_hook =
- FuncRef { contract_id: *DAO_CONTRACT_ID, func_code: DaoFunction::Exec as u8 }
- .to_func_id();
- let dao_owncoins = self
- .get_contract_token_coins(
- &proposal_coinattrs.token_id,
- &dao_spend_hook,
- &proposal.proposal.dao_bulla.inner(),
- )
- .await?;
- if dao_owncoins.is_empty() {
- return Err(Error::Custom(format!(
- "[dao_exec_transfer] Did not find any {} unspent coins owned by this DAO",
- proposal_coinattrs.token_id,
- )))
- }
- // Check DAO balance is sufficient
- if dao_owncoins.iter().map(|x| x.note.value).sum::<u64>() < proposal_coinattrs.value {
- return Err(Error::Custom(format!(
- "[dao_exec_transfer] Not enough DAO balance for token ID: {}",
- proposal_coinattrs.token_id,
- )))
- }
- // Find which DAO coins we can use
- let (spent_coins, change_value) = select_coins(dao_owncoins, proposal_coinattrs.value)?;
- // Now we need to do a lookup for the zkas proof bincodes, and create
- // the circuit objects and proving keys so we can build the transaction.
- // We also do this through the RPC. First we grab the calls from money.
- let zkas_bins = self.lookup_zkas(&MONEY_CONTRACT_ID).await?;
- let Some(mint_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_MINT_NS_V1)
- else {
- return Err(Error::Custom("[dao_exec_transfer] Mint circuit not found".to_string()))
- };
- let Some(burn_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_BURN_NS_V1)
- else {
- return Err(Error::Custom("[dao_exec_transfer] Burn circuit not found".to_string()))
- };
- let Some(fee_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_FEE_NS_V1)
- else {
- return Err(Error::Custom("[dao_exec_transfer] Fee circuit not found".to_string()))
- };
- let mint_zkbin = ZkBinary::decode(&mint_zkbin.1, false)?;
- let burn_zkbin = ZkBinary::decode(&burn_zkbin.1, false)?;
- let fee_zkbin = ZkBinary::decode(&fee_zkbin.1, false)?;
- let mint_circuit = ZkCircuit::new(empty_witnesses(&mint_zkbin)?, &mint_zkbin);
- let burn_circuit = ZkCircuit::new(empty_witnesses(&burn_zkbin)?, &burn_zkbin);
- let fee_circuit = ZkCircuit::new(empty_witnesses(&fee_zkbin)?, &fee_zkbin);
- // Creating Mint, Burn and Fee circuits proving keys
- let mint_pk = ProvingKey::build(mint_zkbin.k, &mint_circuit);
- let burn_pk = ProvingKey::build(burn_zkbin.k, &burn_circuit);
- let fee_pk = ProvingKey::build(fee_zkbin.k, &fee_circuit);
- // Now we grab the DAO bins
- let zkas_bins = self.lookup_zkas(&DAO_CONTRACT_ID).await?;
- let (namespace, early_exec_secret_key) = match early {
- true => {
- (DAO_CONTRACT_ZKAS_EARLY_EXEC_NS, Some(dao.params.early_exec_secret_key.unwrap()))
- }
- false => (DAO_CONTRACT_ZKAS_EXEC_NS, None),
- };
- let Some(dao_exec_zkbin) = zkas_bins.iter().find(|x| x.0 == namespace) else {
- return Err(Error::Custom(format!(
- "[dao_exec_transfer] DAO {namespace} circuit not found"
- )))
- };
- let Some(dao_auth_transfer_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_AUTH_MONEY_TRANSFER_NS)
- else {
- return Err(Error::Custom(
- "[dao_exec_transfer] DAO AuthTransfer circuit not found".to_string(),
- ))
- };
- let Some(dao_auth_transfer_enc_coin_zkbin) =
- zkas_bins.iter().find(|x| x.0 == DAO_CONTRACT_ZKAS_AUTH_MONEY_TRANSFER_ENC_COIN_NS)
- else {
- return Err(Error::Custom(
- "[dao_exec_transfer] DAO AuthTransferEncCoin circuit not found".to_string(),
- ))
- };
- let dao_exec_zkbin = ZkBinary::decode(&dao_exec_zkbin.1, false)?;
- let dao_auth_transfer_zkbin = ZkBinary::decode(&dao_auth_transfer_zkbin.1, false)?;
- let dao_auth_transfer_enc_coin_zkbin =
- ZkBinary::decode(&dao_auth_transfer_enc_coin_zkbin.1, false)?;
- let dao_exec_circuit = ZkCircuit::new(empty_witnesses(&dao_exec_zkbin)?, &dao_exec_zkbin);
- let dao_auth_transfer_circuit =
- ZkCircuit::new(empty_witnesses(&dao_auth_transfer_zkbin)?, &dao_auth_transfer_zkbin);
- let dao_auth_transfer_enc_coin_circuit = ZkCircuit::new(
- empty_witnesses(&dao_auth_transfer_enc_coin_zkbin)?,
- &dao_auth_transfer_enc_coin_zkbin,
- );
- // Creating DAO Exec, AuthTransfer and AuthTransferEncCoin circuits proving keys
- let dao_exec_pk = ProvingKey::build(dao_exec_zkbin.k, &dao_exec_circuit);
- let dao_auth_transfer_pk =
- ProvingKey::build(dao_auth_transfer_zkbin.k, &dao_auth_transfer_circuit);
- let dao_auth_transfer_enc_coin_pk = ProvingKey::build(
- dao_auth_transfer_enc_coin_zkbin.k,
- &dao_auth_transfer_enc_coin_circuit,
- );
- // Fetch our money Merkle tree
- let tree = self.get_money_tree().await?;
- // Retrieve next block height and current block time target,
- // to compute their window.
- let next_block_height = self.get_next_block_height().await?;
- let block_target = self.get_block_target().await?;
- let current_blockwindow = blockwindow(next_block_height, block_target);
- // Check if proposal duration has passed
- if !early &&
- current_blockwindow <
- proposal.proposal.creation_blockwindow +
- proposal.proposal.duration_blockwindows
- {
- return Err(Error::Custom(
- "[dao_exec_transfer] Proposal period has not passed yet".to_string(),
- ))
- }
- // Now we can create the transfer call parameters
- let input_user_data_blind = Blind::random(&mut OsRng);
- let mut inputs = vec![];
- for coin in &spent_coins {
- inputs.push(TransferCallInput {
- coin: coin.clone(),
- merkle_path: tree.witness(coin.leaf_position, 0).unwrap(),
- user_data_blind: input_user_data_blind,
- });
- }
- let mut outputs = vec![];
- outputs.push(proposal_coinattrs.clone());
- let dao_coin_attrs = CoinAttributes {
- public_key: dao.params.dao.notes_public_key,
- value: change_value,
- token_id: proposal_coinattrs.token_id,
- spend_hook: dao_spend_hook,
- user_data: proposal.proposal.dao_bulla.inner(),
- blind: Blind::random(&mut OsRng),
- };
- outputs.push(dao_coin_attrs.clone());
- // Create the transfer call
- let transfer_builder = TransferCallBuilder {
- clear_inputs: vec![],
- inputs,
- outputs,
- mint_zkbin: mint_zkbin.clone(),
- mint_pk: mint_pk.clone(),
- burn_zkbin: burn_zkbin.clone(),
- burn_pk: burn_pk.clone(),
- };
- let (transfer_params, transfer_secrets) = transfer_builder.build()?;
- // Encode the call
- let mut data = vec![MoneyFunction::TransferV1 as u8];
- transfer_params.encode_async(&mut data).await?;
- let transfer_call = ContractCall { contract_id: *MONEY_CONTRACT_ID, data };
- // Create the exec call
- let exec_signature_secret = SecretKey::random(&mut OsRng);
- let exec_builder = DaoExecCall {
- proposal: proposal.proposal.clone(),
- dao: dao.params.dao.clone(),
- yes_vote_value,
- all_vote_value,
- yes_vote_blind,
- all_vote_blind,
- signature_secret: exec_signature_secret,
- current_blockwindow,
- };
- let (exec_params, exec_proofs) = exec_builder.make(
- &dao.params.exec_secret_key.unwrap(),
- &early_exec_secret_key,
- &dao_exec_zkbin,
- &dao_exec_pk,
- )?;
- // Encode the call
- let mut data = vec![DaoFunction::Exec as u8];
- exec_params.encode_async(&mut data).await?;
- let exec_call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
- // Now we can create the auth call
- // Auth module
- let auth_transfer_builder = DaoAuthMoneyTransferCall {
- proposal: proposal.proposal.clone(),
- proposal_coinattrs: vec![proposal_coinattrs],
- dao: dao.params.dao.clone(),
- input_user_data_blind,
- dao_coin_attrs,
- };
- let (auth_transfer_params, auth_transfer_proofs) = auth_transfer_builder.make(
- &dao_auth_transfer_zkbin,
- &dao_auth_transfer_pk,
- &dao_auth_transfer_enc_coin_zkbin,
- &dao_auth_transfer_enc_coin_pk,
- )?;
- // Encode the call
- let mut data = vec![DaoFunction::AuthMoneyTransfer as u8];
- auth_transfer_params.encode_async(&mut data).await?;
- let auth_transfer_call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
- // Create the TransactionBuilder containing above calls
- let mut tx_builder = TransactionBuilder::new(
- ContractCallLeaf { call: exec_call, proofs: exec_proofs },
- vec![
- DarkTree::new(
- ContractCallLeaf { call: auth_transfer_call, proofs: auth_transfer_proofs },
- vec![],
- None,
- None,
- ),
- DarkTree::new(
- ContractCallLeaf { call: transfer_call, proofs: transfer_secrets.proofs },
- vec![],
- None,
- None,
- ),
- ],
- )?;
- // We first have to execute the fee-less tx to gather its used gas, and then we feed
- // it into the fee-creating function.
- let mut tx = tx_builder.build()?;
- let auth_transfer_sigs = tx.create_sigs(&[])?;
- let transfer_sigs = tx.create_sigs(&transfer_secrets.signature_secrets)?;
- let exec_sigs = tx.create_sigs(&[exec_signature_secret])?;
- tx.signatures = vec![auth_transfer_sigs, transfer_sigs, exec_sigs];
- let (fee_call, fee_proofs, fee_secrets) =
- self.append_fee_call(&tx, &tree, &fee_pk, &fee_zkbin, None).await?;
- // Append the fee call to the transaction
- tx_builder.append(ContractCallLeaf { call: fee_call, proofs: fee_proofs }, vec![])?;
- // Now build the actual transaction and sign it with all necessary keys.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&[])?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&transfer_secrets.signature_secrets)?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&[exec_signature_secret])?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&fee_secrets)?;
- tx.signatures.push(sigs);
- Ok(tx)
- }
- /// Execute a DAO generic proposal.
- pub async fn dao_exec_generic(
- &self,
- proposal: &ProposalRecord,
- early: bool,
- ) -> Result<Transaction> {
- if proposal.leaf_position.is_none() ||
- proposal.money_snapshot_tree.is_none() ||
- proposal.nullifiers_smt_snapshot.is_none() ||
- proposal.tx_hash.is_none() ||
- proposal.call_index.is_none()
- {
- return Err(Error::Custom(
- "[dao_exec_generic] Proposal seems to not have been deployed yet".to_string(),
- ))
- }
- // Check proposal is not executed
- if let Some(exec_tx_hash) = proposal.exec_tx_hash {
- return Err(Error::Custom(format!(
- "[dao_exec_generic] Proposal was executed on transaction: {exec_tx_hash}"
- )))
- }
- // Fetch DAO and check its deployed
- let Ok(dao) = self.get_dao_by_bulla(&proposal.proposal.dao_bulla).await else {
- return Err(Error::Custom(format!(
- "[dao_exec_generic] DAO {} was not found",
- proposal.proposal.dao_bulla
- )))
- };
- if dao.leaf_position.is_none() || dao.tx_hash.is_none() || dao.call_index.is_none() {
- return Err(Error::Custom(
- "[dao_exec_generic] DAO seems to not have been deployed yet".to_string(),
- ))
- }
- // Check that we have the exec key
- if dao.params.exec_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_exec_generic] We need the exec secret key to execute proposals for this DAO"
- .to_string(),
- ))
- }
- // If early flag is provided, check that we have the early exec key
- if early && dao.params.early_exec_secret_key.is_none() {
- return Err(Error::Custom(
- "[dao_exec_generic] We need the early exec secret key to execute proposals early for this DAO"
- .to_string(),
- ))
- }
- // Check proposal is approved
- let votes = self.get_dao_proposal_votes(&proposal.bulla()).await?;
- let mut yes_vote_value = 0;
- let mut yes_vote_blind = Blind::ZERO;
- let mut all_vote_value = 0;
- let mut all_vote_blind = Blind::ZERO;
- for vote in votes {
- if vote.vote_option {
- yes_vote_value += vote.all_vote_value;
- };
- yes_vote_blind += vote.yes_vote_blind;
- all_vote_value += vote.all_vote_value;
- all_vote_blind += vote.all_vote_blind;
- }
- let approval_ratio = (yes_vote_value as f64 * 100.0) / all_vote_value as f64;
- let dao_approval_ratio =
- (dao.params.dao.approval_ratio_quot / dao.params.dao.approval_ratio_base) as f64;
- if approval_ratio < dao_approval_ratio {
- return Err(Error::Custom("[dao_exec_generic] Proposal is not approved yet".to_string()))
- }
- // Check the quorum has been met
- if all_vote_value < dao.params.dao.quorum {
- return Err(Error::Custom(
- "[dao_exec_generic] DAO quorum is not reached yet".to_string(),
- ))
- }
- if early && all_vote_value < dao.params.dao.early_exec_quorum {
- return Err(Error::Custom(
- "[dao_exec_generic] DAO early execution quorum is not reached yet".to_string(),
- ))
- }
- // Now we need to do a lookup for the zkas proof bincodes, and create
- // the circuit objects and proving keys so we can build the transaction.
- // We also do this through the RPC. First we grab the calls from money.
- let zkas_bins = self.lookup_zkas(&MONEY_CONTRACT_ID).await?;
- let Some(fee_zkbin) = zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_FEE_NS_V1)
- else {
- return Err(Error::Custom("[dao_exec_generic] Fee circuit not found".to_string()))
- };
- let fee_zkbin = ZkBinary::decode(&fee_zkbin.1, false)?;
- let fee_circuit = ZkCircuit::new(empty_witnesses(&fee_zkbin)?, &fee_zkbin);
- let fee_pk = ProvingKey::build(fee_zkbin.k, &fee_circuit);
- // Now we grab the DAO bins
- let zkas_bins = self.lookup_zkas(&DAO_CONTRACT_ID).await?;
- let (namespace, early_exec_secret_key) = match early {
- true => {
- (DAO_CONTRACT_ZKAS_EARLY_EXEC_NS, Some(dao.params.early_exec_secret_key.unwrap()))
- }
- false => (DAO_CONTRACT_ZKAS_EXEC_NS, None),
- };
- let Some(dao_exec_zkbin) = zkas_bins.iter().find(|x| x.0 == namespace) else {
- return Err(Error::Custom(format!(
- "[dao_exec_generic] DAO {namespace} circuit not found"
- )))
- };
- let dao_exec_zkbin = ZkBinary::decode(&dao_exec_zkbin.1, false)?;
- let dao_exec_circuit = ZkCircuit::new(empty_witnesses(&dao_exec_zkbin)?, &dao_exec_zkbin);
- let dao_exec_pk = ProvingKey::build(dao_exec_zkbin.k, &dao_exec_circuit);
- // Fetch our money Merkle tree
- let tree = self.get_money_tree().await?;
- // Retrieve next block height and current block time target,
- // to compute their window.
- let next_block_height = self.get_next_block_height().await?;
- let block_target = self.get_block_target().await?;
- let current_blockwindow = blockwindow(next_block_height, block_target);
- // Check if proposal duration has passed
- if !early &&
- current_blockwindow <
- proposal.proposal.creation_blockwindow +
- proposal.proposal.duration_blockwindows
- {
- return Err(Error::Custom(
- "[dao_exec_generic] Proposal period has not passed yet".to_string(),
- ))
- }
- // Create the exec call
- let exec_signature_secret = SecretKey::random(&mut OsRng);
- let exec_builder = DaoExecCall {
- proposal: proposal.proposal.clone(),
- dao: dao.params.dao.clone(),
- yes_vote_value,
- all_vote_value,
- yes_vote_blind,
- all_vote_blind,
- signature_secret: exec_signature_secret,
- current_blockwindow,
- };
- let (exec_params, exec_proofs) = exec_builder.make(
- &dao.params.exec_secret_key.unwrap(),
- &early_exec_secret_key,
- &dao_exec_zkbin,
- &dao_exec_pk,
- )?;
- // Encode the call
- let mut data = vec![DaoFunction::Exec as u8];
- exec_params.encode_async(&mut data).await?;
- let exec_call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
- // Create the TransactionBuilder containing above calls
- let mut tx_builder = TransactionBuilder::new(
- ContractCallLeaf { call: exec_call, proofs: exec_proofs },
- vec![],
- )?;
- // We first have to execute the fee-less tx to gather its used gas, and then we feed
- // it into the fee-creating function.
- let mut tx = tx_builder.build()?;
- let exec_sigs = tx.create_sigs(&[exec_signature_secret])?;
- tx.signatures = vec![exec_sigs];
- let (fee_call, fee_proofs, fee_secrets) =
- self.append_fee_call(&tx, &tree, &fee_pk, &fee_zkbin, None).await?;
- // Append the fee call to the transaction
- tx_builder.append(ContractCallLeaf { call: fee_call, proofs: fee_proofs }, vec![])?;
- // Now build the actual transaction and sign it with all necessary keys.
- let mut tx = tx_builder.build()?;
- let sigs = tx.create_sigs(&[exec_signature_secret])?;
- tx.signatures.push(sigs);
- let sigs = tx.create_sigs(&fee_secrets)?;
- tx.signatures.push(sigs);
- Ok(tx)
- }
- }
|