Skip to content

Commit

Permalink
fix: include unpaid store quotes in receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
mickvandijke committed Dec 10, 2024
1 parent 2556e09 commit 61e9b94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
14 changes: 3 additions & 11 deletions autonomi/src/client/payment.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::client::data::PayError;
use crate::client::quote::StoreQuote;
use crate::Client;
use ant_evm::{AttoTokens, EncodedPeerId, EvmWallet, ProofOfPayment, QuoteHash, TxHash};
use std::collections::{BTreeMap, HashMap};
use ant_evm::{AttoTokens, EncodedPeerId, EvmWallet, ProofOfPayment};
use std::collections::HashMap;
use xor_name::XorName;

/// Contains the proof of payments for each XOR address and the amount paid
pub type Receipt = HashMap<XorName, (ProofOfPayment, AttoTokens)>;

pub fn receipt_from_store_quotes_and_payments(
quotes: StoreQuote,
payments: BTreeMap<QuoteHash, TxHash>,
) -> Receipt {
pub fn receipt_from_store_quotes(quotes: StoreQuote) -> Receipt {
let mut receipt = Receipt::new();

for (content_addr, quote_for_address) in quotes.0 {
Expand All @@ -22,11 +19,6 @@ pub fn receipt_from_store_quotes_and_payments(
};

for (peer_id, quote, _amount) in quote_for_address.0 {
// skip quotes that haven't been paid
if !payments.contains_key(&quote.hash()) {
continue;
}

proof_of_payment
.peer_quotes
.push((EncodedPeerId::from(peer_id), quote));
Expand Down
6 changes: 3 additions & 3 deletions autonomi/src/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use crate::client::payment::{receipt_from_store_quotes_and_payments, Receipt};
use crate::client::payment::{receipt_from_store_quotes, Receipt};
use ant_evm::{EvmWallet, ProofOfPayment};
use ant_networking::{GetRecordCfg, PutRecordCfg, VerificationKind};
use ant_protocol::{
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Client {
// TODO: the error might contain some succeeded quote payments as well. These should be returned on err, so that they can be skipped when retrying.
// TODO: retry when it fails?
// Execute chunk payments
let payments = wallet
let _payments = wallet
.pay_for_quotes(quotes.payments())
.await
.map_err(|err| PayError::from(err.0))?;
Expand All @@ -190,7 +190,7 @@ impl Client {
skipped_chunks
);

let receipt = receipt_from_store_quotes_and_payments(quotes, payments);
let receipt = receipt_from_store_quotes(quotes);

Ok(receipt)
}
Expand Down

0 comments on commit 61e9b94

Please sign in to comment.