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

Merge feat/next into main (v13.1.0) #445

Merged
merged 27 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
23fc1f4
Merge pull request #436 from multiversx/merge-main-15-04
popenta Apr 15, 2024
2487cc9
add missing role on fungible token
popenta Apr 15, 2024
bf6a29b
fix typos
popenta Apr 16, 2024
6379548
In "createTransactionForUpgrade()", use the "upgrade" definition, if …
andreibancioiu Apr 16, 2024
b14785d
implement AccountTransactionsFactory
popenta Apr 16, 2024
2d55650
Merge pull request #437 from multiversx/add-missing-role
popenta Apr 16, 2024
c752255
bump version
popenta Apr 16, 2024
8ea8750
Additional unit tests.
andreibancioiu Apr 16, 2024
ad92194
Merge branch 'account-transactions-factory' into abi-upgrade
andreibancioiu Apr 16, 2024
5136ee3
fixes after review
popenta Apr 17, 2024
084873c
make field mandatory
popenta Apr 17, 2024
0a1b012
Merge pull request #440 from multiversx/transfer-role-field-mandatory
popenta Apr 17, 2024
de5925d
Merge pull request #439 from multiversx/account-transactions-factory
popenta Apr 17, 2024
14bbf75
Sketch test (debugging).
andreibancioiu Apr 17, 2024
263555b
Merge pull request #438 from multiversx/abi-upgrade
andreibancioiu Apr 17, 2024
b24c76b
formatting
popenta Apr 17, 2024
327d7a1
Merge pull request #442 from multiversx/formatting-v13-1-0
popenta Apr 17, 2024
7178a88
formatting
popenta Apr 17, 2024
dc922f0
Merge pull request #443 from multiversx/formatting-v13-1-0-part2
popenta Apr 17, 2024
29f1c39
tests formatting
popenta Apr 17, 2024
733dd0d
Merge pull request #444 from multiversx/tests-formatting-v13-1-0
popenta Apr 17, 2024
7a67562
Merge branch 'feat/next' into serializer-435
andreibancioiu Apr 17, 2024
ce867f9
Bit of formatting.
andreibancioiu Apr 17, 2024
0c37c6b
Unit test for "getArgumentsCardinality".
andreibancioiu Apr 17, 2024
a5411b2
Additional testing & debugging.
andreibancioiu Apr 18, 2024
fd5354c
More tests with variadic arguments.
andreibancioiu Apr 18, 2024
1c53e6e
Merge pull request #441 from multiversx/serializer-435
andreibancioiu Apr 18, 2024
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-core",
"version": "13.0.1",
"version": "13.1.0",
"description": "MultiversX SDK for JavaScript and TypeScript",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
4 changes: 2 additions & 2 deletions src/globals.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if ( !global.Buffer ) {
global.Buffer = require('buffer').Buffer;
if (!global.Buffer) {
global.Buffer = require("buffer").Buffer;

Check warning on line 2 in src/globals.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Require statement not part of import statement
}
57 changes: 38 additions & 19 deletions src/relayedTransactionV1Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Transaction } from "./transaction";
import { TransactionPayload } from "./transactionPayload";

const JSONbig = require("json-bigint");

Check warning on line 9 in src/relayedTransactionV1Builder.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Require statement not part of import statement

/**
* @deprecated Use {@link RelayedTransactionsFactory} instead.
Expand Down Expand Up @@ -64,7 +64,7 @@
* (optional) Sets the version of the relayed transaction
*
* @param relayedTxVersion
*/
*/
setRelayedTransactionVersion(relayedTxVersion: TransactionVersion): RelayedTransactionV1Builder {
this.relayedTransactionVersion = relayedTxVersion;
return this;
Expand All @@ -74,7 +74,7 @@
* (optional) Sets the options of the relayed transaction
*
* @param relayedTxOptions
*/
*/
setRelayedTransactionOptions(relayedTxOptions: TransactionOptions): RelayedTransactionV1Builder {
this.relayedTransactionOptions = relayedTxOptions;
return this;
Expand All @@ -97,15 +97,23 @@
* @return Transaction
*/
build(): Transaction {
if (!this.innerTransaction || !this.netConfig || !this.relayerAddress || !this.innerTransaction.getSignature()) {
if (
!this.innerTransaction ||
!this.netConfig ||
!this.relayerAddress ||
!this.innerTransaction.getSignature()
) {
throw new ErrInvalidRelayedV1BuilderArguments();
}

const serializedTransaction = this.prepareInnerTransaction();
const data = `relayedTx@${Buffer.from(serializedTransaction).toString("hex")}`;
const payload = new TransactionPayload(data);

const gasLimit = this.netConfig.MinGasLimit + this.netConfig.GasPerDataByte * payload.length() + this.innerTransaction.getGasLimit().valueOf();
const gasLimit =
this.netConfig.MinGasLimit +
this.netConfig.GasPerDataByte * payload.length() +
this.innerTransaction.getGasLimit().valueOf();
let relayedTransaction = new Transaction({
nonce: this.relayerNonce,
sender: this.relayerAddress,
Expand All @@ -132,21 +140,32 @@
}

const txObject = {
"nonce": this.innerTransaction.getNonce().valueOf(),
"sender": new Address(this.innerTransaction.getSender().bech32()).pubkey().toString("base64"),
"receiver": new Address(this.innerTransaction.getReceiver().bech32()).pubkey().toString("base64"),
"value": BigInt(this.innerTransaction.getValue().toString()),
"gasPrice": this.innerTransaction.getGasPrice().valueOf(),
"gasLimit": this.innerTransaction.getGasLimit().valueOf(),
"data": this.innerTransaction.getData().valueOf().toString("base64"),
"signature": this.innerTransaction.getSignature().toString("base64"),
"chainID": Buffer.from(this.innerTransaction.getChainID().valueOf()).toString("base64"),
"version": this.innerTransaction.getVersion().valueOf(),
"options": this.innerTransaction.getOptions().valueOf() == 0 ? undefined : this.innerTransaction.getOptions().valueOf(),
"guardian": this.innerTransaction.getGuardian().bech32() ? new Address(this.innerTransaction.getGuardian().bech32()).pubkey().toString("base64") : undefined,
"guardianSignature": this.innerTransaction.getGuardianSignature().toString("hex") ? this.innerTransaction.getGuardianSignature().toString("base64") : undefined,
"sndUserName": this.innerTransaction.getSenderUsername() ? Buffer.from(this.innerTransaction.getSenderUsername()).toString("base64") : undefined,
"rcvUserName": this.innerTransaction.getReceiverUsername() ? Buffer.from(this.innerTransaction.getReceiverUsername()).toString("base64") : undefined,
nonce: this.innerTransaction.getNonce().valueOf(),
sender: new Address(this.innerTransaction.getSender().bech32()).pubkey().toString("base64"),
receiver: new Address(this.innerTransaction.getReceiver().bech32()).pubkey().toString("base64"),
value: BigInt(this.innerTransaction.getValue().toString()),
gasPrice: this.innerTransaction.getGasPrice().valueOf(),
gasLimit: this.innerTransaction.getGasLimit().valueOf(),
data: this.innerTransaction.getData().valueOf().toString("base64"),
signature: this.innerTransaction.getSignature().toString("base64"),
chainID: Buffer.from(this.innerTransaction.getChainID().valueOf()).toString("base64"),
version: this.innerTransaction.getVersion().valueOf(),
options:
this.innerTransaction.getOptions().valueOf() == 0
? undefined
: this.innerTransaction.getOptions().valueOf(),
guardian: this.innerTransaction.getGuardian().bech32()
? new Address(this.innerTransaction.getGuardian().bech32()).pubkey().toString("base64")
: undefined,
guardianSignature: this.innerTransaction.getGuardianSignature().toString("hex")
? this.innerTransaction.getGuardianSignature().toString("base64")
: undefined,
sndUserName: this.innerTransaction.getSenderUsername()
? Buffer.from(this.innerTransaction.getSenderUsername()).toString("base64")
: undefined,
rcvUserName: this.innerTransaction.getReceiverUsername()
? Buffer.from(this.innerTransaction.getReceiverUsername()).toString("base64")
: undefined,
};

return JSONbig.stringify(txObject);
Expand Down
16 changes: 12 additions & 4 deletions src/relayedTransactionV2Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ export class RelayedTransactionV2Builder {
* @return Transaction
*/
build(): Transaction {
if (!this.innerTransaction || !this.innerTransactionGasLimit || !this.relayerAddress || !this.netConfig || !this.innerTransaction.getSignature()) {
if (
!this.innerTransaction ||
!this.innerTransactionGasLimit ||
!this.relayerAddress ||
!this.netConfig ||
!this.innerTransaction.getSignature()
) {
throw new ErrInvalidRelayedV2BuilderArguments();
}
if (this.innerTransaction.getGasLimit() != 0) {
Expand All @@ -87,7 +93,7 @@ export class RelayedTransactionV2Builder {
new AddressValue(this.innerTransaction.getReceiver()),
new U64Value(this.innerTransaction.getNonce().valueOf()),
new BytesValue(this.innerTransaction.getData().valueOf()),
new BytesValue(this.innerTransaction.getSignature())
new BytesValue(this.innerTransaction.getSignature()),
]);

const data = `relayedTxV2@${argumentsString}`;
Expand All @@ -98,11 +104,13 @@ export class RelayedTransactionV2Builder {
receiver: this.innerTransaction.getSender(),
value: 0,
gasLimit:
this.innerTransactionGasLimit.valueOf() + this.netConfig.MinGasLimit + this.netConfig.GasPerDataByte * payload.length(),
this.innerTransactionGasLimit.valueOf() +
this.netConfig.MinGasLimit +
this.netConfig.GasPerDataByte * payload.length(),
data: payload,
chainID: this.netConfig.ChainID,
version: this.innerTransaction.getVersion(),
options: this.innerTransaction.getOptions()
options: this.innerTransaction.getOptions(),
});

if (this.relayerNonce) {
Expand Down
23 changes: 15 additions & 8 deletions src/smartcontracts/codeMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export class CodeMetadata {
static ByteZero = {
Upgradeable: 1,
Reserved2: 2,
Readable: 4
Readable: 4,
};

static ByteOne = {
Reserved1: 1,
Payable: 2,
PayableBySc: 4
PayableBySc: 4,
};

/**
Expand All @@ -28,11 +28,16 @@ export class CodeMetadata {
* @param payable Whether the contract is payable
* @param payableBySc Whether the contract is payable by other smart contracts
*/
constructor(upgradeable: boolean = true, readable: boolean = false, payable: boolean = false, payableBySc: boolean = false) {
constructor(
upgradeable: boolean = true,
readable: boolean = false,
payable: boolean = false,
payableBySc: boolean = false,
) {
this.upgradeable = upgradeable;
this.readable = readable;
this.payable = payable;
this.payableBySc = payableBySc
this.payableBySc = payableBySc;
}

static fromBytes(bytes: Uint8Array): CodeMetadata {
Expand All @@ -44,7 +49,7 @@ export class CodeMetadata {
*/
static fromBuffer(buffer: Buffer): CodeMetadata {
if (buffer.length < this.codeMetadataLength) {
throw new Error('Buffer is too short.');
throw new Error("Buffer is too short.");
}

const byteZero = buffer[0];
Expand Down Expand Up @@ -124,14 +129,16 @@ export class CodeMetadata {
upgradeable: this.upgradeable,
readable: this.readable,
payable: this.payable,
payableBySc: this.payableBySc
payableBySc: this.payableBySc,
};
}

equals(other: CodeMetadata): boolean {
return this.upgradeable == other.upgradeable &&
return (
this.upgradeable == other.upgradeable &&
this.readable == other.readable &&
this.payable == other.payable &&
this.payableBySc == other.payableBySc;
this.payableBySc == other.payableBySc
);
}
}
Loading
Loading