1use async_trait::async_trait;
2use redgold_schema::structs::{Address, CurrencyAmount, ExternalTransactionId, MultisigRequest, MultisigResponse, NetworkEnvironment, PartySigningValidation, Proof, PublicKey, SupportedCurrency};
3use redgold_schema::message::Response;
4use redgold_schema::message::Request;
5use redgold_schema::tx::external_tx::ExternalTimedTransaction;
6use redgold_schema::{structs, RgResult};
7use std::collections::HashMap;
8use redgold_schema::keys::words_pass::WordsPass;
9use serde::{Deserialize, Serialize};
10use redgold_schema::parties::PartyInstance;
11
12#[async_trait]
13pub trait PeerBroadcast where Self: Sync + Clone + Send {
14 async fn broadcast(&self, peers: &Vec<PublicKey>, request: Request) -> RgResult<Vec<RgResult<Response>>>;
15 async fn peer_send(&self, peer: &PublicKey, request: Request) -> RgResult<Response>;
16}
17
18#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
19pub struct PartyCreationResult {
20 pub address: Address,
21 pub identifier: Option<String>,
22 pub identifier_index: Option<i64>,
23 pub secret_json: Option<String>
24}
25
26#[async_trait]
27pub trait ExternalNetworkResources where Self : Send + Clone + Sync {
28
29 fn set_network(&mut self, network: &NetworkEnvironment);
30 async fn get_all_tx_for_pk(&self, pk: &PublicKey, currency: SupportedCurrency, filter: Option<NetworkDataFilter>) -> RgResult<Vec<ExternalTimedTransaction>>;
31 async fn get_all_tx_for_address(&self, address: &Address, currency: SupportedCurrency, filter: Option<NetworkDataFilter>)
32 -> RgResult<Vec<ExternalTimedTransaction>>;
33 async fn broadcast(&mut self, pk: &PublicKey, currency: SupportedCurrency, payload: EncodedTransactionPayload) -> RgResult<String>;
34 async fn query_price(&self, time: i64, currency: SupportedCurrency) -> RgResult<f64>;
35 async fn daily_historical_year(&self) -> RgResult<HashMap<SupportedCurrency, Vec<(i64, f64)>>>;
36 async fn send(&mut self, destination: &Address, currency_amount: &CurrencyAmount, broadcast: bool,
37 from: Option<PublicKey>, secret: Option<String>
38 ) -> RgResult<(ExternalTransactionId, String)>;
39 async fn self_balance(&self, currency: SupportedCurrency) -> RgResult<CurrencyAmount>;
40
41 async fn btc_payloads(
43 &self, outputs: Vec<(String, u64)>, public_key: &PublicKey)
44 -> RgResult<(Vec<(Vec<u8>, String)>, PartySigningValidation)>;
45 async fn btc_add_signatures(
46 &mut self, pk: &PublicKey, psbt: String,
47 results: Vec<Proof>, hashes: Vec<(Vec<u8>, String)>) -> RgResult<EncodedTransactionPayload>;
48
49 async fn eth_tx_payload(&self, src: &Address, dst: &Address, amount: &CurrencyAmount, override_gas: Option<CurrencyAmount>) -> RgResult<(Vec<u8>, PartySigningValidation, String)>;
50
51 async fn max_time_price_by(&self, currency: SupportedCurrency, max_time: i64) -> RgResult<Option<f64>>;
52
53 async fn get_balance_no_cache(&self, network: &NetworkEnvironment, currency: &SupportedCurrency, pk: &PublicKey) -> RgResult<CurrencyAmount> where
54 Self: Sync;
55
56 async fn trezor_sign(&self, public: PublicKey, derivation_path: String, t: structs::Transaction) -> RgResult<structs::Transaction>;
57 async fn participate_multisig_send(
58 &self,
59 mr: MultisigRequest,
60 peer_pks: &Vec<PublicKey>,
61 threshold: i64
62 ) -> RgResult<MultisigResponse>;
63 async fn execute_external_multisig_send<B: PeerBroadcast>(
64 &self,
65 party_instance: &PartyInstance,
66 proposer_key: &PublicKey,
67 destination_amounts: Vec<(Address, CurrencyAmount)>,
68 party_address: &Address,
69 peer_pks: &Vec<PublicKey>,
70 broadcast: &B,
71 threshold: i64
72 ) -> RgResult<ExternalTransactionId>;
73
74 async fn get_live_balance(&self, address: &Address) -> RgResult<CurrencyAmount>;
75
76 async fn btc_pubkeys_to_multisig_address(&self, pubkeys: &Vec<PublicKey>, thresh: i64) -> RgResult<Address>;
77 async fn create_multisig_party<B: PeerBroadcast>(
78 &self,
79 cur: &SupportedCurrency,
80 all_pks: &Vec<PublicKey>,
81 self_public_key: &PublicKey,
82 self_private_key_hex: &String,
83 network: &NetworkEnvironment,
84 words_pass: WordsPass,
85 threshold: i64,
86 peer_broadcast: &B,
87 peer_pks: &Vec<PublicKey>
88 ) -> RgResult<Option<PartyCreationResult>>;
89
90
91}
92
93#[allow(dead_code)]
94pub struct NetworkDataFilter {
95 min_block: Option<u64>,
96 min_time: Option<u64>
97}
98
99pub enum EncodedTransactionPayload {
100 JsonPayload(String),
101 BytesPayload(Vec<u8>)
102}