Skip to content
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

Fix transaction sender methods and error handling #167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ExtendedTransactionBuilder extends TransactionBuilder {
}

//Override TransactionSender.send to use the node resolution
send(confirmationThreshold: number, timeout: number) {
send(confirmationThreshold?: number, timeout?: number) {
this.core.requestNode((endpoint) => this.sender.send(this, endpoint, confirmationThreshold, timeout));
}

Expand Down
16 changes: 7 additions & 9 deletions src/transaction_sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export default class TransactionSender {

this.timeout = undefined;
this.nbConfirmationReceived = 0;

return this;
}

/**
Expand Down Expand Up @@ -71,19 +69,19 @@ export default class TransactionSender {
break;

default:
throw "Event " + event + " is not supported";
throw new Error("Event " + event + " is not supported");
}

return this;
}

async send(tx: TransactionBuilder, endpoint: string, confirmationThreshold: number = 100, timeout: number = 60) {
if (confirmationThreshold < 0 && confirmationThreshold > 100) {
throw "'confirmationThreshold' must be an integer between 0 and 100";
if (confirmationThreshold < 0 || confirmationThreshold > 100) {
throw new Error("'confirmationThreshold' must be an integer between 0 and 100");
}

if (timeout <= 0) {
throw "'timeout' must be an integer greater than 0";
throw new Error("'timeout' must be an integer greater than 0");
}

const txAddress = uint8ArrayToHex(tx.address);
Expand Down Expand Up @@ -148,7 +146,7 @@ export default class TransactionSender {
break;

default:
throw "Event " + event + " is not supported";
throw new Error("Event " + event + " is not supported");
}
} else {
absinthe.cancel(this.absintheSocket as AbsintheSocket, this.confirmationNotifier);
Expand Down Expand Up @@ -179,7 +177,7 @@ async function waitConfirmations(
const notifier = absinthe.send(absintheSocket, operation);
return absinthe.observe(absintheSocket, notifier, (result: any) => {
if (result.data.transactionConfirmed) {
const { nbConfirmations: nbConfirmations, maxConfirmations: maxConfirmations } = result.data.transactionConfirmed;
const { nbConfirmations, maxConfirmations } = result.data.transactionConfirmed;

handler(nbConfirmations, maxConfirmations);
}
Expand All @@ -198,7 +196,7 @@ async function waitError(address: string | Uint8Array, absintheSocket: any, hand
const notifier = absinthe.send(absintheSocket, operation);
return absinthe.observe(absintheSocket, notifier, (result: any) => {
if (result.data.transactionError) {
const { context: context, reason: reason } = result.data.transactionError;
const { context, reason } = result.data.transactionError;
handler(context, reason);
}
});
Expand Down
Loading