-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
src/smartcontracts/smartContract.ts
Outdated
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({ |
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.
Transaction.fromDraft
function could be used here. Try to see where else can be used
@@ -33,6 +33,7 @@ describe("test smart contract interactor", function () { | |||
let interaction = new Interaction(contract, dummyFunction, []); | |||
|
|||
let transaction = interaction | |||
.withSender(alice.address) |
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.
Correct.
sender: IAddress; | ||
tokenIdentifier: string; | ||
supplyToMint: BigNumber.Value; | ||
}): TransactionIntent { | ||
supplyToBurn: BigNumber.Value; |
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.
👍
...(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())], |
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.
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()
.
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.
Or we can even define a boolToHex
function, near utf8ToHex
and so on.
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.
Created a boolToHex()
function.
@@ -1,7 +1,7 @@ | |||
import { BigNumber } from "bignumber.js"; | |||
import { DEFAULT_HRP } from "../constants"; | |||
|
|||
export class TransactionIntentsFactoryConfig { | |||
export class TransactionsFactoryConfig { |
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.
Thinking out loud - do we need chainID
?
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.
As discussed, we will keep the chainID.
data: new TransactionPayload(Buffer.from(intent.data!)), | ||
chainID: chainID | ||
}); | ||
let transaction = Transaction.fromDraft(draftTx); |
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.
Can also be const
(even if we mutate its inner state).
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'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(), ""); |
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.
Perhaps also add asserts for the other empty fields (e.g. nonce, gas price, signature etc.)?
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.
added new asserts.
/** | ||
* Creates a new Transaction object from a DraftTransaction. | ||
*/ |
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.
Formatting / indentation.
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.
Fixed it
sender: Address.fromBech32(draft.sender), | ||
receiver: Address.fromBech32(draft.receiver), | ||
gasLimit: new BigNumber(draft.gasLimit).toNumber(), | ||
chainID: "", |
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.
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() |
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.
new TransactionPayload()
accepts buffers, as well.
Updated the transaction factories according to the sdk-specs.