@@ -13,10 +13,7 @@ import {
1313 DistributionExtension ,
1414} from '@cosmjs/stargate' ;
1515
16- import { LumWallet } from '../wallet' ;
17- import { Message } from '../messages' ;
18- import { sha256 , generateAuthInfo , generateSignDoc , generateSignDocBytes , generateTxBytes } from '../utils' ;
19- import { BroadcastTxCommitResponse , TxResponse , TxSearchParams , BlockResponse , Account , Coin , Fee } from '../types' ;
16+ import { LumWallet , LumUtils , LumTypes , LumMessages } from '..' ;
2017
2118export class LumClient {
2219 readonly tmClient : Tendermint34Client ;
@@ -102,7 +99,7 @@ export class LumClient {
10299 *
103100 * @param height block height to get (default to current height)
104101 */
105- getBlock = async ( height ?: number ) : Promise < BlockResponse > => {
102+ getBlock = async ( height ?: number ) : Promise < LumTypes . BlockResponse > => {
106103 const response = await this . tmClient . block ( height ) ;
107104 return response ;
108105 } ;
@@ -112,7 +109,7 @@ export class LumClient {
112109 *
113110 * @param address wallet address
114111 */
115- getAccount = async ( address : string ) : Promise < Account | null > => {
112+ getAccount = async ( address : string ) : Promise < LumTypes . Account | null > => {
116113 const account = await this . queryClient . auth . account ( address ) ;
117114 if ( ! account ) {
118115 return null ;
@@ -129,7 +126,7 @@ export class LumClient {
129126 *
130127 * @param address wallet address
131128 */
132- getAccountUnverified = async ( address : string ) : Promise < Account | null > => {
129+ getAccountUnverified = async ( address : string ) : Promise < LumTypes . Account | null > => {
133130 const account = await this . queryClient . auth . unverified . account ( address ) ;
134131 if ( ! account ) {
135132 return null ;
@@ -147,7 +144,7 @@ export class LumClient {
147144 * @param address wallet address
148145 * @param searchDenom Coin denomination (ex: lum)
149146 */
150- getBalance = async ( address : string , searchDenom : string ) : Promise < Coin | null > => {
147+ getBalance = async ( address : string , searchDenom : string ) : Promise < LumTypes . Coin | null > => {
151148 const balance = await this . queryClient . bank . balance ( address , searchDenom ) ;
152149 return balance ? coinFromProto ( balance ) : null ;
153150 } ;
@@ -158,7 +155,7 @@ export class LumClient {
158155 * @param address wallet address
159156 * @param searchDenom Coin denomination (ex: lum)
160157 */
161- getBalanceUnverified = async ( address : string , searchDenom : string ) : Promise < Coin | null > => {
158+ getBalanceUnverified = async ( address : string , searchDenom : string ) : Promise < LumTypes . Coin | null > => {
162159 const balance = await this . queryClient . bank . unverified . balance ( address , searchDenom ) ;
163160 return balance ? coinFromProto ( balance ) : null ;
164161 } ;
@@ -168,7 +165,7 @@ export class LumClient {
168165 *
169166 * @param address wallet address
170167 */
171- getAllBalancesUnverified = async ( address : string ) : Promise < Coin [ ] > => {
168+ getAllBalancesUnverified = async ( address : string ) : Promise < LumTypes . Coin [ ] > => {
172169 const balances = await this . queryClient . bank . unverified . allBalances ( address ) ;
173170 return balances . map ( coinFromProto ) ;
174171 } ;
@@ -178,15 +175,15 @@ export class LumClient {
178175 *
179176 * @param searchDenom Coin denomination (ex: lum)
180177 */
181- getSupply = async ( searchDenom : string ) : Promise < Coin | null > => {
178+ getSupply = async ( searchDenom : string ) : Promise < LumTypes . Coin | null > => {
182179 const supply = await this . queryClient . bank . unverified . supplyOf ( searchDenom ) ;
183180 return supply ? coinFromProto ( supply ) : null ;
184181 } ;
185182
186183 /**
187184 * Get all coins supplies
188185 */
189- getAllSupplies = async ( ) : Promise < Coin [ ] > => {
186+ getAllSupplies = async ( ) : Promise < LumTypes . Coin [ ] > => {
190187 const supplies = await this . queryClient . bank . unverified . totalSupply ( ) ;
191188 return supplies . map ( coinFromProto ) ;
192189 } ;
@@ -197,7 +194,7 @@ export class LumClient {
197194 * @param hash transaction hash to retrieve
198195 * @param includeProof whether or not to include proof of the transaction inclusion in the block
199196 */
200- getTx = async ( hash : Uint8Array , includeProof ?: boolean ) : Promise < TxResponse | null > => {
197+ getTx = async ( hash : Uint8Array , includeProof ?: boolean ) : Promise < LumTypes . TxResponse | null > => {
201198 const result = await this . tmClient . tx ( { hash : hash , prove : includeProof } ) ;
202199 return result ;
203200 } ;
@@ -216,10 +213,10 @@ export class LumClient {
216213 * @param perPage results per pages (default to 30)
217214 * @param includeProof whether or not to include proofs of the transactions inclusion in the block
218215 */
219- searchTx = async ( queries : string [ ] , page = 1 , perPage = 30 , includeProof ?: boolean ) : Promise < TxResponse [ ] > => {
216+ searchTx = async ( queries : string [ ] , page = 1 , perPage = 30 , includeProof ?: boolean ) : Promise < LumTypes . TxResponse [ ] > => {
220217 const results = await Promise . all ( queries . map ( ( q ) => this . txsQuery ( { query : q , page : page , per_page : perPage , prove : includeProof } ) ) ) ;
221218 const seenHashes : Uint8Array [ ] = [ ] ;
222- const uniqueResults : TxResponse [ ] = [ ] ;
219+ const uniqueResults : LumTypes . TxResponse [ ] = [ ] ;
223220 for ( let r = 0 ; r < results . length ; r ++ ) {
224221 for ( let t = 0 ; t < results [ r ] . length ; t ++ ) {
225222 const tx = results [ r ] [ t ] ;
@@ -237,9 +234,9 @@ export class LumClient {
237234 *
238235 * @param params Search params
239236 */
240- private txsQuery = async ( params : TxSearchParams ) : Promise < TxResponse [ ] > => {
237+ private txsQuery = async ( params : LumTypes . TxSearchParams ) : Promise < LumTypes . TxResponse [ ] > => {
241238 const results = await this . tmClient . txSearch ( params ) ;
242- return results . txs as TxResponse [ ] ;
239+ return results . txs as LumTypes . TxResponse [ ] ;
243240 } ;
244241
245242 /**
@@ -250,20 +247,18 @@ export class LumClient {
250247 * @param fee requested fee
251248 * @param memo optional memo for the transaction
252249 */
253- signTx = async ( wallet : LumWallet , messages : Message [ ] , fee : Fee , memo ?: string ) : Promise < Uint8Array > => {
254- const account = await this . getAccount ( wallet . address ) ;
250+ signTx = async ( wallet : LumWallet , messages : LumMessages . Message [ ] , fee : LumTypes . Fee , memo ?: string ) : Promise < Uint8Array > => {
251+ const account = await this . getAccount ( wallet . getAddress ( ) ) ;
255252 if ( ! account ) {
256253 throw new Error ( 'Account not found' ) ;
257254 }
258255 const { accountNumber, sequence } = account ;
259256 const chainId = await this . getChainId ( ) ;
260257
261- const authInfo = generateAuthInfo ( wallet . publicKey , fee , sequence ) ;
262- const signDoc = generateSignDoc ( messages , memo , authInfo , chainId , accountNumber ) ;
263- const signBytes = generateSignDocBytes ( signDoc ) ;
264- const hashedMessage = sha256 ( signBytes ) ;
265- const signature = await wallet . signTransaction ( hashedMessage ) ;
266- return generateTxBytes ( signDoc , signature ) ;
258+ const authInfo = LumUtils . generateAuthInfo ( wallet . getPublicKey ( ) , fee , sequence ) ;
259+ const signDoc = LumUtils . generateSignDoc ( messages , memo , authInfo , chainId , accountNumber ) ;
260+ const signature = await wallet . signTransaction ( signDoc ) ;
261+ return LumUtils . generateTxBytes ( signDoc , signature ) ;
267262 } ;
268263
269264 /**
@@ -272,7 +267,7 @@ export class LumClient {
272267 *
273268 * @param tx signed transaction to broadcast
274269 */
275- broadcastTx = async ( tx : Uint8Array ) : Promise < BroadcastTxCommitResponse > => {
270+ broadcastTx = async ( tx : Uint8Array ) : Promise < LumTypes . BroadcastTxCommitResponse > => {
276271 const response = await this . tmClient . broadcastTxCommit ( { tx } ) ;
277272 return response ;
278273 } ;
@@ -285,7 +280,7 @@ export class LumClient {
285280 * @param fee requested fee
286281 * @param memo optional memo for the transaction
287282 */
288- signAndBroadcastTx = async ( wallet : LumWallet , messages : Message [ ] , fee : Fee , memo ?: string ) : Promise < BroadcastTxCommitResponse > => {
283+ signAndBroadcastTx = async ( wallet : LumWallet , messages : LumMessages . Message [ ] , fee : LumTypes . Fee , memo ?: string ) : Promise < LumTypes . BroadcastTxCommitResponse > => {
289284 const signedTx = await this . signTx ( wallet , messages , fee , memo ) ;
290285 return this . broadcastTx ( signedTx ) ;
291286 } ;
0 commit comments