-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from cosmology-tech/refactor-tx-builder
Refactor tx builder
- Loading branch information
Showing
6 changed files
with
64 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { AuthInfo } from '@interchainjs/cosmos-types/cosmos/tx/v1beta1/tx'; | ||
import { ITxBuilderContext } from '@interchainjs/types'; | ||
import { BaseTxBuilderContext, ITxBuilderContext } from '@interchainjs/types'; | ||
|
||
/** | ||
* Context for the transaction builder. | ||
*/ | ||
export class BaseCosmosTxBuilderContext<Signer> | ||
extends BaseTxBuilderContext<Signer> | ||
implements ITxBuilderContext<Signer> | ||
{ | ||
constructor(public signer: Signer, public authInfo?: AuthInfo) {} | ||
constructor(public signer: Signer) { | ||
super(signer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* ISigBuilder is an interface for building signature from document. | ||
*/ | ||
export interface ISigBuilder<Doc = unknown, Sig = unknown> { | ||
/** | ||
* build signature from document. | ||
*/ | ||
buildSignature(doc: Doc): Sig | Promise<Sig>; | ||
} | ||
|
||
/** | ||
* ITxBuilder is an interface for building signed transaction document. | ||
*/ | ||
export interface ITxBuilder<SignArgs = unknown, SignResp = unknown> { | ||
buildSignedTxDoc(args: SignArgs): Promise<SignResp>; | ||
} | ||
|
||
/** | ||
* ITxBuilderContext is a context object for building transaction document. | ||
*/ | ||
export interface ITxBuilderContext<Signer = unknown> { | ||
signer?: Signer; | ||
|
||
/** | ||
* set staging data. | ||
* @param data - staging data | ||
*/ | ||
setStagingData(key: string, data: unknown): void; | ||
|
||
/** | ||
* get staging data. | ||
*/ | ||
getStagingData<TStaging>(key: string): TStaging; | ||
} | ||
|
||
/** | ||
* BaseTxBuilderContext is a base class for ITxBuilderContext. | ||
*/ | ||
export class BaseTxBuilderContext<Signer> implements ITxBuilderContext<Signer> { | ||
private stagingData: Record<string, unknown> = {}; | ||
|
||
constructor(public signer?: Signer) {} | ||
|
||
setStagingData(key: string, data: unknown): void { | ||
this.stagingData[key] = data; | ||
} | ||
|
||
getStagingData<TStaging>(key: string): TStaging { | ||
return this.stagingData[key] as TStaging; | ||
} | ||
} |