-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor: Fullnode facade to Typescript #972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce08173
f5e1f28
74b746e
7502c46
45810b8
caa69b4
4f1b19f
63f7b9b
9673109
427ef03
9c5f997
eeb9655
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,6 +187,16 @@ | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Guard that asserts `this.wallet` is not null and narrows its type for the caller. | ||
| * Throws a TypeError if wallet is not set. | ||
| */ | ||
| private assertWallet(): asserts this is { wallet: HathorWallet } { | ||
| if (!this.wallet) { | ||
| throw new TypeError('Wallet is required to build nano contract transactions.'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Set vertex type | ||
| * | ||
|
|
@@ -217,6 +227,7 @@ | |
| async executeDeposit( | ||
| action: NanoContractAction | ||
| ): Promise<{ inputs: IDataInput[]; outputs: IDataOutput[] }> { | ||
| this.assertWallet(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most methods in this file assume The use of this |
||
| if (action.type !== NanoContractActionType.DEPOSIT) { | ||
| throw new NanoContractTransactionError( | ||
| "Can't execute a deposit with an action which type is different than deposit." | ||
|
|
@@ -313,6 +324,7 @@ | |
| * @inner | ||
| */ | ||
| executeWithdrawal(action: NanoContractAction): IDataOutput | null { | ||
| this.assertWallet(); | ||
| if (action.type !== NanoContractActionType.WITHDRAWAL) { | ||
| throw new NanoContractTransactionError( | ||
| "Can't execute a withdrawal with an action which type is different than withdrawal." | ||
|
|
@@ -381,6 +393,7 @@ | |
| async executeGrantAuthority( | ||
| action: NanoContractAction | ||
| ): Promise<{ inputs: IDataInput[]; outputs: IDataOutput[] }> { | ||
| this.assertWallet(); | ||
| if (action.type !== NanoContractActionType.GRANT_AUTHORITY) { | ||
| throw new NanoContractTransactionError( | ||
| "Can't execute a grant authority with an action which type is different than grant authority." | ||
|
|
@@ -449,6 +462,7 @@ | |
| * @inner | ||
| */ | ||
| executeAcquireAuthority(action: NanoContractAction): IDataOutput | null { | ||
| this.assertWallet(); | ||
| if (action.type !== NanoContractActionType.ACQUIRE_AUTHORITY) { | ||
| throw new NanoContractTransactionError( | ||
| "Can't execute an acquire authority with an action which type is different than acquire authority." | ||
|
|
@@ -481,6 +495,7 @@ | |
| * @inner | ||
| */ | ||
| async verify() { | ||
| this.assertWallet(); | ||
| if (this.method === NANO_CONTRACTS_INITIALIZE_METHOD && !this.blueprintId) { | ||
| // Initialize needs the blueprint ID | ||
| throw new NanoContractTransactionError('Missing blueprint id. Parameter blueprintId in data'); | ||
|
|
@@ -622,6 +637,7 @@ | |
| outputs: IDataOutput[], | ||
| tokens: string[] | ||
| ): Promise<Transaction | CreateTokenTransaction> { | ||
| this.assertWallet(); | ||
| if (this.vertexType === NanoContractVertexType.TRANSACTION) { | ||
| return transactionUtils.createTransactionFromData( | ||
| { | ||
|
|
@@ -682,6 +698,7 @@ | |
| * @inner | ||
| */ | ||
| async build(): Promise<Transaction> { | ||
| this.assertWallet(); | ||
| let inputs; | ||
| let outputs; | ||
| let tokens; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ export type ISendOutput = ISendDataOutput | ISendTokenOutput; | |
| * 'unexpected-error': if an unexpected error happens; | ||
| * */ | ||
| export default class SendTransaction extends EventEmitter { | ||
| wallet: HathorWallet; | ||
| wallet: HathorWallet | null; | ||
|
||
|
|
||
| storage: IStorage | null; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was the closest I could get to the type of the error. Since this can be only
HathorWalletornull, I decided for a type error.Do you think a simple
Errorwould be more adequate here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create a custom error or use an existing one.
WalletTypeError or WalletError for instance.