-
Notifications
You must be signed in to change notification settings - Fork 314
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
modified the AssembledTransaction and it's tests #1075
Changes from all commits
8e8b7ae
dbf1f58
0c556e7
016535b
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 |
---|---|---|
|
@@ -378,10 +378,10 @@ export class AssembledTransaction<T> { | |
* Serialize the AssembledTransaction to a base64-encoded XDR string. | ||
*/ | ||
toXDR(): string { | ||
if(!this.built) throw new Error( | ||
"Transaction has not yet been simulated; " + | ||
"call `AssembledTransaction.simulate` first.", | ||
); | ||
if (!this.built) throw new Error( | ||
"Transaction has not yet been simulated; " + | ||
"call `AssembledTransaction.simulate` first.", | ||
); | ||
return this.built?.toEnvelope().toXDR('base64'); | ||
} | ||
|
||
|
@@ -405,17 +405,21 @@ export class AssembledTransaction<T> { | |
} | ||
const method = invokeContractArgs.functionName().toString('utf-8'); | ||
const txn = new AssembledTransaction( | ||
{ ...options, | ||
{ | ||
...options, | ||
Comment on lines
-408
to
+409
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. Nor these |
||
method, | ||
parseResultXdr: (result: xdr.ScVal) => | ||
spec.funcResToNative(method, result), | ||
} | ||
); | ||
); | ||
Comment on lines
-413
to
+414
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. Nor this |
||
txn.built = built; | ||
return txn; | ||
} | ||
|
||
private constructor(public options: AssembledTransactionOptions<T>) { | ||
if (!options.publicKey) { | ||
throw new Error("Public key not provided"); | ||
} | ||
Comment on lines
+420
to
+422
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. See previous comments about this. The logic is wrong. We do not want this. |
||
this.options.simulate = this.options.simulate ?? true; | ||
this.server = new Server(this.options.rpcUrl, { | ||
allowHttp: this.options.allowHttp ?? false, | ||
|
@@ -441,16 +445,19 @@ export class AssembledTransaction<T> { | |
* simulate: false, | ||
* }) | ||
*/ | ||
// AssembledTransaction.ts | ||
PoulavBhowmick03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
PoulavBhowmick03 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+448
to
+449
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. This is noise |
||
static async build<T>( | ||
options: AssembledTransactionOptions<T>, | ||
): Promise<AssembledTransaction<T>> { | ||
if (!options.publicKey) { | ||
throw new Error("Public key not provided. Have you forgotten to set the `publicKey` in AssembledTransactionOptions?"); | ||
} | ||
|
||
Comment on lines
+453
to
+456
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. This is wrong |
||
const tx = new AssembledTransaction(options); | ||
const contract = new Contract(options.contractId); | ||
|
||
const account = await getAccount( | ||
options, | ||
tx.server | ||
); | ||
const account = await getAccount(options, tx.server); | ||
Comment on lines
-450
to
+460
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. This is wrong |
||
|
||
tx.raw = new TransactionBuilder(account, { | ||
fee: options.fee ?? BASE_FEE, | ||
|
@@ -464,6 +471,7 @@ export class AssembledTransaction<T> { | |
return tx; | ||
} | ||
|
||
|
||
PoulavBhowmick03 marked this conversation as resolved.
Show resolved
Hide resolved
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. This is noise |
||
private static async buildFootprintRestoreTransaction<T>( | ||
options: AssembledTransactionOptions<T>, | ||
sorobanData: SorobanDataBuilder | xdr.SorobanTransactionData, | ||
|
@@ -482,9 +490,9 @@ export class AssembledTransaction<T> { | |
return tx; | ||
} | ||
|
||
simulate = async ({ restore }: {restore?: boolean} = {}): Promise<this> => { | ||
if (!this.built){ | ||
if(!this.raw) { | ||
simulate = async ({ restore }: { restore?: boolean } = {}): Promise<this> => { | ||
if (!this.built) { | ||
if (!this.raw) { | ||
throw new Error( | ||
"Transaction has not yet been assembled; " + | ||
"call `AssembledTransaction.build` first." | ||
|
@@ -609,32 +617,30 @@ export class AssembledTransaction<T> { | |
force = false, | ||
signTransaction = this.options.signTransaction, | ||
}: { | ||
/** | ||
* If `true`, sign and send the transaction even if it is a read call | ||
*/ | ||
force?: boolean; | ||
/** | ||
* You must provide this here if you did not provide one before | ||
*/ | ||
PoulavBhowmick03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
signTransaction?: ClientOptions["signTransaction"]; | ||
} = {}): Promise<void> => { | ||
if (!this.built) { | ||
throw new Error("Transaction has not yet been simulated"); | ||
throw new Error("Transaction has not yet been simulated."); | ||
} | ||
|
||
if (!force && this.isReadCall) { | ||
throw new AssembledTransaction.Errors.NoSignatureNeeded( | ||
"This is a read call. It requires no signature or sending. " + | ||
"Use `force: true` to sign and send anyway." | ||
"This is a read call. It requires no signature or sending. Use `force: true` to sign and send anyway." | ||
); | ||
} | ||
|
||
if (!signTransaction) { | ||
throw new AssembledTransaction.Errors.NoSigner( | ||
"You must provide a signTransaction function, either when calling " + | ||
"`signAndSend` or when initializing your Client" | ||
"You must provide a `signTransaction` function, either when calling `signAndSend` or when initializing your Client." | ||
); | ||
} | ||
// Ensure publicKey is provided for non-read calls | ||
if (!this.options.publicKey) { | ||
throw new Error( | ||
"Public key not provided. Have you forgotten to set the `publicKey` in AssembledTransactionOptions?" | ||
Comment on lines
+638
to
+641
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. It looks like this is the only needed change here. Everything except this block seems either like anti-linting or outright error. Maybe there's a test of this specific logic that should stay; I again didn't get that far. Can you please force-push a single commit to this branch with only these specific changes? We do not want to merge anything else. I see you pushed right to your
|
||
); | ||
} | ||
|
||
// filter out contracts, as these are dealt with via cross contract calls | ||
const sigsNeeded = this.needsNonInvokerSigningBy().filter(id => !id.startsWith('C')); | ||
|
@@ -645,8 +651,7 @@ export class AssembledTransaction<T> { | |
); | ||
} | ||
|
||
const timeoutInSeconds = | ||
this.options.timeoutInSeconds ?? DEFAULT_TIMEOUT; | ||
const timeoutInSeconds = this.options.timeoutInSeconds ?? DEFAULT_TIMEOUT; | ||
this.built = TransactionBuilder.cloneFrom(this.built!, { | ||
fee: this.built!.fee, | ||
timebounds: undefined, | ||
|
@@ -668,12 +673,13 @@ export class AssembledTransaction<T> { | |
) as Tx; | ||
}; | ||
|
||
|
||
PoulavBhowmick03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Sends the transaction to the network to return a `SentTransaction` that | ||
* keeps track of all the attempts to fetch the transaction. | ||
*/ | ||
async send(){ | ||
if(!this.signed){ | ||
async send() { | ||
if (!this.signed) { | ||
throw new Error("The transaction has not yet been signed. Run `sign` first, or use `signAndSend` instead."); | ||
} | ||
const sent = await SentTransaction.init(undefined, this); | ||
|
@@ -699,7 +705,7 @@ export class AssembledTransaction<T> { | |
*/ | ||
signTransaction?: ClientOptions["signTransaction"]; | ||
} = {}): Promise<SentTransaction<T>> => { | ||
if(!this.signed){ | ||
if (!this.signed) { | ||
await this.sign({ force, signTransaction }); | ||
} | ||
return this.send(); | ||
|
@@ -813,7 +819,7 @@ export class AssembledTransaction<T> { | |
* If you have a pro use-case and need to override the default `authorizeEntry` function, rather than using the one in @stellar/stellar-base, you can do that! Your function needs to take at least the first argument, `entry: xdr.SorobanAuthorizationEntry`, and return a `Promise<xdr.SorobanAuthorizationEntry>`. | ||
* | ||
* Note that you if you pass this, then `signAuthEntry` will be ignored. | ||
*/ | ||
*/ | ||
authorizeEntry?: typeof stellarBaseAuthorizeEntry; | ||
} = {}): Promise<void> => { | ||
if (!this.built) | ||
|
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.
None of these changes should be included