Skip to content

Commit

Permalink
Merge pull request #445 from multiversx/feat/next
Browse files Browse the repository at this point in the history
Merge feat/next into main (v13.1.0)
  • Loading branch information
andreibancioiu authored Apr 18, 2024
2 parents cb4fd81 + 1c53e6e commit b877bbe
Show file tree
Hide file tree
Showing 31 changed files with 1,449 additions and 507 deletions.
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;
}
57 changes: 38 additions & 19 deletions src/relayedTransactionV1Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class RelayedTransactionV1Builder {
* (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 @@ export class RelayedTransactionV1Builder {
* (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 @@ export class RelayedTransactionV1Builder {
* @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 @@ export class RelayedTransactionV1Builder {
}

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

0 comments on commit b877bbe

Please sign in to comment.