Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
pools: Update smart contract balance after UTXO transfer
Browse files Browse the repository at this point in the history
If the UTXO transfer from contract to P2PK or contract succeeds,
zero the balance of the smart contract as the contract no longer
holds any funds.
  • Loading branch information
altonen committed Nov 18, 2021
1 parent 9012d3b commit c1a4b94
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pallets/pp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ fn send_p2pk_tx<T: Config>(
ensure!(fund_info.funds >= value, "Caller doesn't have enough funds");
let outpoints = fund_info.utxos.iter().map(|x| x.0).collect::<Vec<H256>>();

T::Utxo::submit_c2pk_tx(caller, dest, value, &outpoints)
T::Utxo::submit_c2pk_tx(caller, dest, value, &outpoints).map(|_| {
<ContractBalances<T>>::mutate(&caller, |info| {
info.as_mut().unwrap().utxos = Vec::new();
info.as_mut().unwrap().funds = 0;
});
})
}

/// Create Contract-to-Contract transfer that allows smart contracts to
Expand All @@ -169,7 +174,12 @@ fn send_c2c_tx<T: Config>(
))?;
let outpoints = fund_info.utxos.iter().map(|x| x.0).collect::<Vec<H256>>();

T::Utxo::submit_c2c_tx(caller, dest, fund_info.funds, data, &outpoints)
T::Utxo::submit_c2c_tx(caller, dest, fund_info.funds, data, &outpoints).map(|_| {
<ContractBalances<T>>::mutate(&caller, |info| {
info.as_mut().unwrap().utxos = Vec::new();
info.as_mut().unwrap().funds = 0;
});
})
}

impl<T: Config> ProgrammablePoolApi for Pallet<T>
Expand Down

0 comments on commit c1a4b94

Please sign in to comment.