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

Update transaction factories to match the sdk-specs #339

Merged
merged 7 commits into from
Oct 23, 2023

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Oct 16, 2023

Updated the transaction factories according to the sdk-specs.

@popenta popenta self-assigned this Oct 16, 2023
@popenta popenta marked this pull request as draft October 16, 2023 14:06
@popenta popenta marked this pull request as ready for review October 17, 2023 10:04
danielailie
danielailie previously approved these changes Oct 17, 2023
danielailie
danielailie previously approved these changes Oct 17, 2023
config: config,
abi: this.abi
});

const bytecode = Uint8Array.from(Buffer.from(code.toString(), 'hex'));
const metadataAsJson = this.getMetadataPropertiesAsObject(codeMetadata);

const intent = scIntentFactory.createTransactionIntentForUpgrade({
const intent = scIntentFactory.createTransactionForUpgrade({
Copy link

@CiprianDraghici CiprianDraghici Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transaction.fromDraft function could be used here. Try to see where else can be used

src/draftTransaction.ts Show resolved Hide resolved
src/draftTransaction.ts Show resolved Hide resolved
@@ -33,6 +33,7 @@ describe("test smart contract interactor", function () {
let interaction = new Interaction(contract, dummyFunction, []);

let transaction = interaction
.withSender(alice.address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

sender: IAddress;
tokenIdentifier: string;
supplyToMint: BigNumber.Value;
}): TransactionIntent {
supplyToBurn: BigNumber.Value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

...(options.canChangeOwner ? [utf8ToHex("canChangeOwner"), this.trueAsHex] : []),
...(options.canUpgrade ? [utf8ToHex("canUpgrade"), this.trueAsHex] : []),
...(options.canAddSpecialRoles ? [utf8ToHex("canAddSpecialRoles"), this.trueAsHex] : []),
...[utf8ToHex("canUpgrade"), utf8ToHex(String(options.canUpgrade).toLowerCase())],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the following, instead?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString

E.g. new Boolean(...), or directly options.canUpgrade.toString().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can even define a boolToHex function, near utf8ToHex and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a boolToHex() function.

@@ -1,7 +1,7 @@
import { BigNumber } from "bignumber.js";
import { DEFAULT_HRP } from "../constants";

export class TransactionIntentsFactoryConfig {
export class TransactionsFactoryConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking out loud - do we need chainID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we will keep the chainID.

data: new TransactionPayload(Buffer.from(intent.data!)),
chainID: chainID
});
let transaction = Transaction.fromDraft(draftTx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also be const (even if we mutate its inner state).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now const.

assert.equal(transaction.getGasLimit().valueOf(), 56000);
assert.equal(transaction.getValue().toString(), "1000000000000000000");
assert.equal(transaction.getData().toString(), "test");
assert.equal(transaction.getChainID().valueOf(), "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also add asserts for the other empty fields (e.g. nonce, gas price, signature etc.)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new asserts.

Comment on lines +156 to +158
/**
* Creates a new Transaction object from a DraftTransaction.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting / indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it

sender: Address.fromBech32(draft.sender),
receiver: Address.fromBech32(draft.receiver),
gasLimit: new BigNumber(draft.gasLimit).toNumber(),
chainID: "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a bit unfortunate at this moment (since chainID is required on the Transaction).

gasLimit: new BigNumber(draft.gasLimit).toNumber(),
chainID: "",
value: draft.value ?? 0,
data: draft.data ? new TransactionPayload(Buffer.from(draft.data)) : new TransactionPayload()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new TransactionPayload() accepts buffers, as well.

@popenta popenta merged commit b2c0025 into feat/factories Oct 23, 2023
1 check passed
@popenta popenta deleted the update-transaction-factories branch October 23, 2023 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants