Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b8472b0
Update palelt name from runtime
didiermis Oct 11, 2022
2b4dbc1
Change one field name "balance" from ExpenditureData<T> to "expenditu…
didiermis Oct 11, 2022
6135d2f
Update ExpednitureData structure to store the given expenditure amount
didiermis Oct 11, 2022
9324211
change field description for TransactionData structure for feedback
didiermis Oct 12, 2022
253e07a
Remove creator field from DrawdownData<T>
didiermis Oct 12, 2022
7d07f3a
remove creator field from TransactionData structure
didiermis Oct 12, 2022
169f509
add field documents for DrawdownData structure for future bulk upload…
didiermis Oct 12, 2022
d9a9328
Remove unnecesarry storagemaps
didiermis Oct 13, 2022
396e532
Delete all flow related to budgets (not expenditures budgets) it was …
didiermis Oct 13, 2022
2c0fcd9
Convert to an Option feeback field from TransactionData<T>
didiermis Oct 13, 2022
dbdf549
Update storagemap getters name
didiermis Oct 13, 2022
a8269dc
Update enum CURD to -> CUDActions because the read method is never us…
didiermis Oct 13, 2022
45cbfe3
I added the inital setup for the transactions flow.
didiermis Oct 14, 2022
f4acc9f
Wrap into Option all fields from transactions boundedvec because the…
didiermis Oct 14, 2022
14c3921
Fix #187
tlacloc Oct 14, 2022
9fd5c88
Hanlde error in case the function do_execute_transactions do not rece…
didiermis Oct 14, 2022
e622dd5
Delete enum project type
didiermis Oct 14, 2022
1f8c414
Delete field project_type from ProjectData<T> structure
didiermis Oct 14, 2022
681abd7
add registration_date for ProjectData structure
didiermis Oct 14, 2022
f9273c6
Remove project_type from extrinsic projects_create_project
didiermis Oct 14, 2022
67597b3
Update flow for do_create_project
didiermis Oct 14, 2022
e17c160
Remove validation match project type to validate expenditure type
didiermis Oct 14, 2022
78ec6a4
Fix #207
didiermis Oct 14, 2022
21ed8ca
Fix typos & allow creation date to be editable when editing a project
didiermis Oct 14, 2022
567fc5c
Allow the administrator to edit any field for a selected project
didiermis Oct 17, 2022
302884b
Merge pull request #201 from hashed-io/feature/proxy-migration
tlacloc Oct 17, 2022
302b45f
Merge pull request #206 from hashed-io/fix/nbv/fix_status
tlacloc Oct 17, 2022
e1760a7
update runtime
tlacloc Oct 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions pallets/bitcoin-vaults/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<T: Config> Pallet<T> {
}

pub fn do_save_psbt(signer: T::AccountId, proposal_id: [u8;32], signature_payload: BoundedVec<u8, T::PSBTMaxLen>) -> DispatchResult{
// validations: proposal exists, signer is member of vault, proposal is pending,
// validations: proposal exists, signer is member of vault, proposal is pending,
let vault_id = <Proposals<T>>::get(proposal_id).ok_or(Error::<T>::ProposalNotFound)?.vault_id;
let vault = <Vaults<T>>::get(vault_id).ok_or(Error::<T>::VaultNotFound)?;
ensure!(vault.is_vault_member(&signer), Error::<T>::SignerPermissionsNeeded);
Expand All @@ -121,6 +121,9 @@ impl<T: Config> Pallet<T> {
let signed_already = p.signed_psbts.iter().find(|&signature|{ signature.signer ==signer }).is_some();
ensure!(!signed_already, Error::<T>::AlreadySigned);
p.signed_psbts.try_push(signature).map_err(|_| Error::<T>::ExceedMaxCosignersPerVault)?;
if p.signed_psbts.len() as u32 == vault.threshold {
p.status.clone_from(&ProposalStatus::ReadyToFinalize(false));
}
}
Ok(())
})?;
Expand All @@ -136,9 +139,9 @@ impl<T: Config> Pallet<T> {
// can be called by any vault signer
ensure!(vault.is_vault_member(&signer), Error::<T>::SignerPermissionsNeeded);
// if its finalized then fire error "already finalized" or "already broadcasted"
ensure!(proposal.status.eq(&ProposalStatus::Pending) || proposal.status.eq(&ProposalStatus::Finalized),
ensure!(proposal.status.eq(&ProposalStatus::Pending) || proposal.status.eq(&ProposalStatus::Finalized),
Error::<T>::PendingProposalRequired );
// signs must be greater or equal than threshold
// signs must be greater or equal than threshold
ensure!(proposal.signed_psbts.len() as u32 >= vault.threshold, Error::<T>::NotEnoughSignatures);
// set status to: ready to be finalized
<Proposals<T>>::try_mutate::<_,(),DispatchError,_>(proposal_id, |proposal|{
Expand Down Expand Up @@ -174,7 +177,7 @@ impl<T: Config> Pallet<T> {
}

/*---- Offchain extrinsics ----*/

pub fn do_insert_descriptors(vault_id: [u8;32], descriptors: Descriptors<T::OutputDescriptorMaxLen>, status: BDKStatus<T::VaultDescriptionMaxLen>) -> DispatchResult {
<Vaults<T>>::try_mutate(vault_id, | v |{
match v {
Expand Down Expand Up @@ -225,8 +228,8 @@ impl<T: Config> Pallet<T> {
pub fn get_pending_vaults() -> Vec<[u8; 32]> {
<Vaults<T>>::iter()
.filter_map(|(entry, vault)| {
if vault.descriptors.output_descriptor.is_empty() &&
(vault.offchain_status.eq(&BDKStatus::<T::VaultDescriptionMaxLen>::Pending) ||
if vault.descriptors.output_descriptor.is_empty() &&
(vault.offchain_status.eq(&BDKStatus::<T::VaultDescriptionMaxLen>::Pending) ||
vault.offchain_status.eq(&BDKStatus::<T::VaultDescriptionMaxLen>::RecoverableError(
BoundedVec::<u8,T::VaultDescriptionMaxLen>::default() )) ) {
Some(entry)
Expand All @@ -240,8 +243,8 @@ impl<T: Config> Pallet<T> {
pub fn get_pending_proposals() -> Vec<[u8; 32]>{
<Proposals<T>>::iter()
.filter_map(|(id, proposal)|{
if proposal.psbt.is_empty() &&
(proposal.offchain_status.eq(&BDKStatus::<T::VaultDescriptionMaxLen>::Pending) ||
if proposal.psbt.is_empty() &&
(proposal.offchain_status.eq(&BDKStatus::<T::VaultDescriptionMaxLen>::Pending) ||
proposal.offchain_status.eq(&BDKStatus::<T::VaultDescriptionMaxLen>::RecoverableError(
BoundedVec::<u8,T::VaultDescriptionMaxLen>::default() )) ){
Some(id)
Expand Down Expand Up @@ -353,7 +356,7 @@ impl<T: Config> Pallet<T> {
};
body.push(("threshold".chars().collect::<Vec<char>>(), JsonValue::Number(threshold)));
let vault_signers = vault.cosigners.clone().to_vec();

//get the xpub for each cosigner
let xpubs = Self::get_accounts_xpubs(vault_signers).map_err(|_|
Self::build_offchain_err(false, "One of the cosigner xpubs wasn't found"))?;
Expand Down Expand Up @@ -428,7 +431,7 @@ impl<T: Config> Pallet<T> {
vault_payload.change_descriptor.clone_from(&descriptors.1);
},
Err(status) => {vault_payload.status.clone_from(&status)},
};
};
// Build offchain vaults struct and push it to a Vec
generated_vaults.push(vault_payload);
});
Expand Down Expand Up @@ -492,7 +495,7 @@ impl<T: Config> Pallet<T> {
Ok(response_body)
}

pub fn gen_proposals_payload_by_bulk(pending_proposals : Vec<[u8;32]>, api_endpoint: Vec<u8>,
pub fn gen_proposals_payload_by_bulk(pending_proposals : Vec<[u8;32]>, api_endpoint: Vec<u8>,
json_builder: &dyn Fn([u8;32])-> Result<Vec<u8>,OffchainStatus>
) -> Vec<SingleProposalPayload>{
let mut generated_proposals = Vec::<SingleProposalPayload>::new();
Expand Down Expand Up @@ -531,7 +534,7 @@ impl<T: Config> Pallet<T> {
let mapped_signatures: Vec<JsonValue> = proposal.signed_psbts.iter().map(|psbt|{
JsonValue::String(str::from_utf8(&psbt.signature).unwrap_or_default().chars().collect())
}).collect();

let broadcast= match proposal.status{
ProposalStatus::ReadyToFinalize(flag) => flag,
_ => false,
Expand All @@ -544,7 +547,7 @@ impl<T: Config> Pallet<T> {
// // Parse the JSON and print the resulting lite-json structure.
Ok(jsonSerialize::format(&json_object, 4) )
}

// pub fn bdk_gen_finalized_proposal(proposal_id: [u8;32])-> Result<Vec<u8>,OffchainStatus >{
// let raw_json = Self::gen_finalize_json_body(proposal_id)?;
// let request_body =
Expand All @@ -564,7 +567,7 @@ impl<T: Config> Pallet<T> {
// let mut finalized_proposals = Vec::<SingleProposalPayload>::new();
// finalized_proposals
// }

fn build_offchain_err(recoverable: bool, msj: &str )-> OffchainStatus{
let bounded_msj = msj.as_bytes().to_vec();
match recoverable{
Expand Down Expand Up @@ -638,4 +641,4 @@ impl<T: Config> BlockNumberProvider for Pallet<T> {
fn current_block_number() -> Self::BlockNumber {
<frame_system::Pallet<T>>::block_number()
}
}
}
Loading