Skip to content

Commit

Permalink
fix: receipt type and headers
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Feb 27, 2024
1 parent 91d6bed commit 6c81ce3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
21 changes: 9 additions & 12 deletions file-exchange/src/download_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@ use std::sync::{Arc, Mutex as StdMutex};
use std::time::Duration;
use tokio::sync::Mutex;

use crate::{config::DownloaderArgs, discover, graphql};
use crate::{config::OnChainArgs, errors::Error, transaction_manager::TransactionManager};
use crate::{
config::{DownloaderArgs, OnChainArgs},
discover::{Finder, ServiceEndpoint},
download_client::signer::Access,
};
use crate::{
graphql::escrow_query::escrow_balance,
errors::Error,
graphql::{allocation_id, escrow_query::escrow_balance},
manifest::{
file_hasher::verify_chunk, ipfs::IpfsClient, manifest_fetcher::read_bundle, Bundle,
FileManifestMeta,
},
transaction_manager::TransactionManager,
util::build_wallet,
};

use crate::util::build_wallet;

use self::signer::ReceiptSigner;

pub mod signer;
Expand Down Expand Up @@ -303,10 +300,11 @@ impl Downloader {
PaymentMethod::PaidQuery(signer) => {
let receipt = signer
.receipt_signer
.create_receipt(graphql::allocation_id(receiver), &discover::Finder::fees())
.create_receipt(allocation_id(receiver), &Finder::fees())
.await?;
Ok((
HeaderName::from_str("Scalar-Receipt").unwrap(),
// HeaderName::from_str("Scalar-Receipt").unwrap(),
HeaderName::from_str("scalar-receipt").unwrap(),
receipt.serialize(),
))
}
Expand Down Expand Up @@ -489,11 +487,10 @@ impl Downloader {
if (estimated_buying_power_in_bytes as u64) < total_bytes {
let msg = format!("Balance is not enough to purchase {} bytes, look at the error message to see top-up recommendations for each account", estimated_buying_power_in_bytes);
return Err(Error::PricingError(msg));
} else {
tracing::info!("Balance is enough to purchase the file, go ahead to download");
}
};

tracing::info!("Balance is enough to purchase the file, go ahead to download");
Ok(())
}
}
Expand Down
21 changes: 20 additions & 1 deletion file-exchange/src/download_client/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl ReceiptSigner {
&self,
allocation_id: Address,
fee: &GRT,
) -> Result<TapReceipt, Error> {
) -> Result<ScalarReceipt, Error> {
let nonce = rand::thread_rng().next_u64();
let timestamp_ns = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
Expand All @@ -69,5 +69,24 @@ impl ReceiptSigner {
EIP712SignedMessage::new(&self.domain, receipt, &wallet)
.await
.map_err(|e| Error::ContractError(e.to_string()))
.map(ScalarReceipt::TAP)
}
}

pub enum ScalarReceipt {
TAP(EIP712SignedMessage<Receipt>),
}

impl ScalarReceipt {
pub fn allocation(&self) -> Address {
match self {
ScalarReceipt::TAP(receipt) => receipt.message.allocation_id,
}
}

pub fn serialize(&self) -> String {
match self {
ScalarReceipt::TAP(receipt) => serde_json::to_string(&receipt).unwrap(),
}
}
}

0 comments on commit 6c81ce3

Please sign in to comment.