/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with
TALER; see the file COPYING. If not, see
*/
use std::{
fmt::Debug,
path::{Path, PathBuf},
str::FromStr,
};
use common::{
api_common::Amount,
config::TalerConfig,
currency::{Currency, CurrencyEth},
log::{fail, OrFail},
metadata::{InMetadata, OutMetadata},
postgres,
url::Url,
};
use ethereum_types::{Address, H160, H256, U256, U64};
use rpc::{hex::Hex, Rpc, RpcClient, RpcStream, Transaction};
use rpc_utils::default_data_dir;
use serde::de::DeserializeOwned;
use taler_util::{eth_payto_addr, taler_to_eth};
pub mod rpc;
mod rpc_utils;
pub mod taler_util;
/// An extended geth JSON-RPC api client who can send and retrieve metadata with their transaction
pub trait RpcExtended: RpcClient {
/// Perform a wire credit
fn credit(
&mut self,
from: Address,
to: Address,
value: U256,
reserve_pub: [u8; 32],
) -> rpc::Result {
let metadata = InMetadata::Credit { reserve_pub };
self.send_transaction(&rpc::TransactionRequest {
from,
to,
value,
nonce: None,
gas_price: None,
data: Hex(metadata.encode()),
})
}
/// Perform a wire debit
fn debit(
&mut self,
from: Address,
to: Address,
value: U256,
wtid: [u8; 32],
url: Url,
) -> rpc::Result {
let metadata = OutMetadata::Debit { wtid, url };
self.send_transaction(&rpc::TransactionRequest {
from,
to,
value,
nonce: None,
gas_price: None,
data: Hex(metadata.encode().or_fail(|e| format!("{}", e))),
})
}
/// Perform a Taler bounce
fn bounce(&mut self, hash: H256, bounce_fee: U256) -> rpc::Result