2 个版本
0.5.6 | 2023年12月18日 |
---|---|
0.5.5 | 2023年12月18日 |
#26 in #dapp
72KB
1K SLoC
Tesseract Substrate 协议
完整的协议规范请见此处
客户端初始化
use tesseract::client::Tesseract;
use tesseract::client::delegate::SingleTransportDelegate;
use tesseract_protocol_substrate::Substrate;
let client_tesseract = Tesseract::new(client::delegate::SingleTransportDelegate::arc())
.transport(your_transport_here);
let client_service = client_tesseract.service(Substrate::Protocol); //you can start calling methods of protocol
ID
tesseract_protocol_substrate::Substrate::Protocol
定义
协议
#[async_trait]
pub trait SubstrateService {
async fn get_account(self: Arc<Self>, account_type: AccountType) -> Result<GetAccountResponse>;
async fn sign_transaction(
self: Arc<Self>,
account_type: AccountType,
account_path: &str,
extrinsic_data: &[u8],
extrinsic_metadata: &[u8],
extrinsic_types: &[u8],
) -> Result<Vec<u8>>;
}
账户类型
pub enum AccountType {
Ed25519 = 1,
Sr25519 = 2,
Ecdsa = 3,
}
获取账户响应
pub struct GetAccountResponse {
pub public_key: Vec<u8>, // Public key of the account. 32/33 bytes depending of the AccountType
pub path: String, // Derivation path or id of the account.
}
方法
get_account
请求钱包获取用户账户(公钥)。
let account = Arc::clone(&client_service).get_account(AccountType::Sr25519).await;
sign_transaction
请求钱包对交易进行签名。返回签名字节。
let signature = Arc::clone(&client_service).sign_transaction(
AccountType::Sr25519,
account.path,
// <tx bytes>,
// <medatata bytes>,
// <registry bytes>
).await;
依赖项
~1.6–2.6MB
~56K SLoC