-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2364 from mickvandijke/feat-autonomi-prepaid-uploads
feat(autonomi): support prepaid put operations
- Loading branch information
Showing
23 changed files
with
506 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::client::data::PayError; | ||
use crate::Client; | ||
use sn_evm::{EvmWallet, ProofOfPayment}; | ||
use std::collections::HashMap; | ||
use xor_name::XorName; | ||
|
||
/// Contains the proof of payment for XOR addresses. | ||
pub type Receipt = HashMap<XorName, ProofOfPayment>; | ||
|
||
/// Payment options for data payments. | ||
#[derive(Clone)] | ||
pub enum PaymentOption { | ||
Wallet(EvmWallet), | ||
Receipt(Receipt), | ||
} | ||
|
||
impl From<EvmWallet> for PaymentOption { | ||
fn from(value: EvmWallet) -> Self { | ||
PaymentOption::Wallet(value) | ||
} | ||
} | ||
|
||
impl From<&EvmWallet> for PaymentOption { | ||
fn from(value: &EvmWallet) -> Self { | ||
PaymentOption::Wallet(value.clone()) | ||
} | ||
} | ||
|
||
impl From<Receipt> for PaymentOption { | ||
fn from(value: Receipt) -> Self { | ||
PaymentOption::Receipt(value) | ||
} | ||
} | ||
|
||
impl Client { | ||
pub(crate) async fn pay_for_content_addrs( | ||
&self, | ||
content_addrs: impl Iterator<Item = XorName>, | ||
payment_option: PaymentOption, | ||
) -> Result<Receipt, PayError> { | ||
match payment_option { | ||
PaymentOption::Wallet(wallet) => { | ||
let (receipt, _) = self.pay(content_addrs, &wallet).await?; | ||
Ok(receipt) | ||
} | ||
PaymentOption::Receipt(receipt) => Ok(receipt), | ||
} | ||
} | ||
} |
Oops, something went wrong.