|
| 1 | +# 中心化钱包业务流程 |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +- 地址生成流程 |
| 6 | + - 业务方按照需求调度签名机生成密钥对,私钥存储在签名机里面,公钥通过接口返回 |
| 7 | + - 业务调用 gRPC 接口,传入公钥列表,生成地址,multichain-sync-utxo/multichain-sync-account 调度底层服务根据公钥生成地址,并返回地址列表给到业务方。 |
| 8 | +- 扫链业务流程 |
| 9 | + - 充值时:synchronizer 服务监听区块解析交易处理入库 |
| 10 | + - 充值:出金地址是外部地址,入金地址是交易所用户地址 |
| 11 | + - 提现:出金地址是热钱包地址,入金地址是外部地址 |
| 12 | + - 归集:出金地址是用户地址,入金地址是热钱包地址 |
| 13 | + - 热转温:出金地址是热钱包地址,入金地址是温钱包地址 |
| 14 | + - 温转热:出金地址是温钱包地址,入金地址是热钱包地址 |
| 15 | +- 提现 |
| 16 | + - 调用 multichain-sync 的 BuildUnSignTransaction, 构建 32 个字节的 MessageHash |
| 17 | + - 使用 MessageHash 去签名机里面进行签名,返回来 signature |
| 18 | + - 使用交易的 requestId 和签名发送到 multichain-sync, 构建的完整的并发送到区块网络 |
| 19 | + - multichain-sync 的提现任务不断扫交易并发送到区块链,发送完成之后通知业务层,交易已发送 |
| 20 | + - 扫到提现交易之后再次通知业务层提现成功 |
| 21 | +- 归集, 热转温和温转热业务逻辑和提现差不多流程 |
| 22 | + |
| 23 | +## 一.统一 RPC 服务 Gateway |
| 24 | + |
| 25 | + |
| 26 | +## 二.wallet-chain-utxo 实现的接口 |
| 27 | +``` |
| 28 | +GetSupportChains(req *utxo.SupportChainsRequest) (*utxo.SupportChainsResponse, error) |
| 29 | +ConvertAddress(req *utxo.ConvertAddressRequest) (*utxo.ConvertAddressResponse, error) |
| 30 | +ValidAddress(req *utxo.ValidAddressRequest) (*utxo.ValidAddressResponse, error) |
| 31 | +GetFee(req *utxo.FeeRequest) (*utxo.FeeResponse, error) |
| 32 | +GetAccount(req *utxo.AccountRequest) (*utxo.AccountResponse, error) |
| 33 | +GetUnspentOutputs(req *utxo.UnspentOutputsRequest) (*utxo.UnspentOutputsResponse, error) |
| 34 | +GetBlockByNumber(req *utxo.BlockNumberRequest) (*utxo.BlockResponse, error) |
| 35 | +GetBlockByHash(req *utxo.BlockHashRequest) (*utxo.BlockResponse, error) |
| 36 | +GetBlockHeaderByHash(req *utxo.BlockHeaderHashRequest) (*utxo.BlockHeaderResponse, error) |
| 37 | +GetBlockHeaderByNumber(req *utxo.BlockHeaderNumberRequest) (*utxo.BlockHeaderResponse, error) |
| 38 | +SendTx(req *utxo.SendTxRequest) (*utxo.SendTxResponse, error) |
| 39 | +GetTxByAddress(req *utxo.TxAddressRequest) (*utxo.TxAddressResponse, error) |
| 40 | +GetTxByHash(req *utxo.TxHashRequest) (*utxo.TxHashResponse, error) |
| 41 | +BuildUnSignTransaction(req *utxo.UnSignTransactionRequest) (*utxo.UnSignTransactionResponse, error) |
| 42 | +BuildSignedTransaction(req *utxo.SignedTransactionRequest) (*utxo.SignedTransactionResponse, error) |
| 43 | +DecodeTransaction(req *utxo.DecodeTransactionRequest) (*utxo.DecodeTransactionResponse, error) |
| 44 | +VerifySignedTransaction(req *utxo.VerifyTransactionRequest) (*utxo.VerifyTransactionResponse, error) |
| 45 | +``` |
| 46 | +- GetSupportChains: 可以查询是否支持这条链 |
| 47 | +- ConvertAddress: 公钥导出地址 |
| 48 | +- ValidAddress:判断地址格式是否正确 |
| 49 | +- GetFee: 预估手续费 |
| 50 | +- GetAccount:获取账户相关的信息,例如:余额 |
| 51 | +- GetUnspentOutputs:获取未花费的输入输出列表 |
| 52 | +- GetBlockByNumber:根据区块号获取区块的信息,包含交易列表,若传空,获取到的是最新区块,若传入区块数,获取到的区块的信息 |
| 53 | +- GetBlockByHash:根据区块哈希获取区块的信息,包含交易列表 |
| 54 | +- GetBlockHeaderByHash:根据区块哈希获取区块头信息 |
| 55 | +- GetBlockHeaderByNumber:根据区块号获取区块头信息 |
| 56 | +- SendTx:广播签名的交易 |
| 57 | +- GetTxByAddress: 根据地址获取该地址相关的交易记录 |
| 58 | +- GetTxByHash:根据 TxHash 获取交易详情 |
| 59 | +- BuildUnSignTransaction:根据交易数据生成待签名的 32 字节的 MessageHash |
| 60 | +- BuildSignedTransaction: 用签名机返回的 signature 和交易信息一起构建出完整的交易 |
| 61 | +- DecodeTransaction:将 rawTx decode 出原始的交易 |
| 62 | +- VerifySignedTransaction:签名的交易的验证 |
| 63 | + |
| 64 | +## 三.wallet-chain-account 实现的接口 |
| 65 | +``` |
| 66 | +type IChainAdaptor interface { |
| 67 | + GetSupportChains(req *account.SupportChainsRequest) (*account.SupportChainsResponse, error) |
| 68 | + ConvertAddress(req *account.ConvertAddressRequest) (*account.ConvertAddressResponse, error) |
| 69 | + ValidAddress(req *account.ValidAddressRequest) (*account.ValidAddressResponse, error) |
| 70 | + GetBlockByNumber(req *account.BlockNumberRequest) (*account.BlockResponse, error) |
| 71 | + GetBlockByHash(req *account.BlockHashRequest) (*account.BlockResponse, error) |
| 72 | + GetBlockHeaderByHash(req *account.BlockHeaderHashRequest) (*account.BlockHeaderResponse, error) |
| 73 | + GetBlockHeaderByNumber(req *account.BlockHeaderNumberRequest) (*account.BlockHeaderResponse, error) |
| 74 | + GetAccount(req *account.AccountRequest) (*account.AccountResponse, error) |
| 75 | + GetFee(req *account.FeeRequest) (*account.FeeResponse, error) |
| 76 | + SendTx(req *account.SendTxRequest) (*account.SendTxResponse, error) |
| 77 | + GetTxByAddress(req *account.TxAddressRequest) (*account.TxAddressResponse, error) |
| 78 | + GetTxByHash(req *account.TxHashRequest) (*account.TxHashResponse, error) |
| 79 | + GetBlockByRange(req *account.BlockByRangeRequest) (*account.BlockByRangeResponse, error) |
| 80 | + BuildUnSignTransaction(req *account.UnSignTransactionRequest) (*account.UnSignTransactionResponse, error) |
| 81 | + BuildSignedTransaction(req *account.SignedTransactionRequest) (*account.SignedTransactionResponse, error) |
| 82 | + DecodeTransaction(req *account.DecodeTransactionRequest) (*account.DecodeTransactionResponse, error) |
| 83 | + VerifySignedTransaction(req *account.VerifyTransactionRequest) (*account.VerifyTransactionResponse, error) |
| 84 | + GetExtraData(req *account.ExtraDataRequest) (*account.ExtraDataResponse, error) |
| 85 | +} |
| 86 | +``` |
| 87 | +- GetSupportChains: 可以查询是否支持这条链 |
| 88 | +- ConvertAddress: 公钥到处地址 |
| 89 | +- ValidAddress:判断地址格式是否正确 |
| 90 | +- GetFee: 预估手续费 |
| 91 | +- GetAccount:获取账户相关的信息,例如:余额 |
| 92 | +- GetBlockByNumber:根据区块号获取区块的信息,包含交易列表,若传空,获取到的是最新区块,若传入区块数,获取到的区块的信息 |
| 93 | +- GetBlockByHash:根据区块哈希获取区块的信息,包含交易列表 |
| 94 | +- GetBlockHeaderByHash:根据区块哈希获取区块头信息 |
| 95 | +- GetBlockHeaderByNumber:根据区块号获取区块头信息 |
| 96 | +- GetBlockByRange: 根据 star 和 end 区块号获取这些区块区间的区块信息 |
| 97 | +- SendTx:广播签名的交易 |
| 98 | +- GetTxByAddress: 根据地址获取该地址相关的交易记录 |
| 99 | +- GetTxByHash:根据 TxHash 获取交易详情 |
| 100 | +- BuildUnSignTransaction:根据交易数据生成待签名的 32 字节的 MessageHash |
| 101 | +- BuildSignedTransaction: 用签名机返回的 signature 和交易信息一起构建出完整的交易 |
| 102 | +- DecodeTransaction:将 rawTx decode 出原始的交易 |
| 103 | +- VerifySignedTransaction:签名的交易的验证 |
| 104 | +- GetExtraData: 预留接口 |
| 105 | + |
| 106 | +## 四.multichain-sync-account/utxo 服务 |
| 107 | +``` |
| 108 | +service BusinessMiddleWireServices { |
| 109 | + rpc businessRegister(BusinessRegisterRequest) returns (BusinessRegisterResponse) {} |
| 110 | + rpc exportAddressesByPublicKeys(ExportAddressesRequest) returns (ExportAddressesResponse) {} |
| 111 | + rpc buildUnSignTransaction(UnSignWithdrawTransactionRequest) returns(UnSignWithdrawTransactionResponse){} |
| 112 | + rpc buildSignedTransaction(SignedWithdrawTransactionRequest) returns(SignedWithdrawTransactionResponse){} |
| 113 | + rpc setTokenAddress(SetTokenAddressRequest) returns (SetTokenAddressResponse) {} |
| 114 | +} |
| 115 | +``` |
| 116 | +- businessRegister:第三方业务需要进行注册,注册到系统之后才能使用整个钱包服务 |
| 117 | +- exportAddressesByPublicKeys:根据公钥批量生成地址 |
| 118 | +- createUnSignTransaction: 根据交易数据生成待签名的 32 字节的 MessageHash |
| 119 | +- buildUnSignTransaction: 用签名机返回的 signature 和交易信息一起构建出完整的交易 |
| 120 | +- setTokenAddress: 业务根据自己的需求配置需要支持的 token |
| 121 | + |
| 122 | + |
0 commit comments