tesseract_protocol_substrate/
lib.rs1#![feature(async_closure)]
18
19#[cfg(feature = "client")]
20pub mod client;
21
22#[cfg(feature = "service")]
23pub mod service;
24
25use async_trait::async_trait;
26use std::sync::Arc;
27
28use serde::{Deserialize, Serialize};
29
30use tesseract_one::error::Result;
31use tesseract_one::Protocol;
32
33#[derive(Clone, Copy)]
34pub enum Substrate {
35 Protocol,
36}
37
38impl Default for Substrate {
39 fn default() -> Self {
40 Self::Protocol
41 }
42}
43
44impl Protocol for Substrate {
45 fn id(&self) -> String {
46 "substrate-v1".to_owned()
47 }
48}
49
50#[repr(u8)]
51#[derive(Serialize, Deserialize, Clone, Copy)]
52pub enum AccountType {
53 Ed25519 = 1,
54 Sr25519 = 2,
55 Ecdsa = 3,
56}
57
58pub mod method_names {
59 pub const GET_ACCOUNT: &str = "get_account";
60 pub const SIGN_TRANSACTION: &str = "sign_transaction";
61}
62
63#[derive(Serialize, Deserialize, Clone, Copy)]
64pub struct GetAccountRequest {
65 pub account_type: AccountType, }
67
68#[derive(Serialize, Deserialize, Clone)]
69pub struct GetAccountResponse {
70 pub public_key: Vec<u8>, pub path: String, }
73
74#[derive(Serialize, Deserialize, Clone)]
75pub struct SignTransactionRequest {
76 pub account_type: AccountType, pub account_path: String, pub extrinsic_data: Vec<u8>, pub extrinsic_metadata: Vec<u8>, pub extrinsic_types: Vec<u8>, }
82
83#[derive(Serialize, Deserialize, Clone)]
84pub struct SignTransactionResponse {
85 pub signature: Vec<u8>, }
87
88#[async_trait]
89pub trait SubstrateService {
90 async fn get_account(self: Arc<Self>, account_type: AccountType) -> Result<GetAccountResponse>;
91 async fn sign_transaction(
92 self: Arc<Self>,
93 account_type: AccountType,
94 account_path: &str,
95 extrinsic_data: &[u8],
96 extrinsic_metadata: &[u8],
97 extrinsic_types: &[u8],
98 ) -> Result<Vec<u8>>;
99}