Skip to content

Commit

Permalink
Merge pull request #231 from ElrondNetwork/feat/erdjs-v11
Browse files Browse the repository at this point in the history
Release erdjs 11
  • Loading branch information
ccorcoveanu authored Jul 29, 2022
2 parents 0551dde + 48e3832 commit 2d0a737
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 706 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ All notable changes will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## Unreleased
- TBD

## 11.0.0
- [Breaking change: Sender is now mandatory when constructing a transaction](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/TBD)
- Switched to MIT license
## 10.2.7
- [Update reference to keccak](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/222)

Expand Down
675 changes: 6 additions & 669 deletions LICENSE

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elrondnetwork/erdjs",
"version": "10.2.7",
"version": "11.0.0",
"description": "Smart Contracts interaction framework",
"main": "out/index.js",
"types": "out/index.d.js",
Expand All @@ -24,9 +24,9 @@
"prepare": "npm run compile"
},
"author": "ElrondNetwork",
"license": "GPL-3.0-or-later",
"license": "MIT",
"dependencies": {
"@elrondnetwork/transaction-decoder": "0.1.0",
"@elrondnetwork/transaction-decoder": "1.0.0",
"bech32": "1.1.4",
"bignumber.js": "9.0.1",
"blake2b": "2.1.3",
Expand All @@ -36,8 +36,8 @@
"protobufjs": "6.11.3"
},
"devDependencies": {
"@elrondnetwork/erdjs-network-providers": "0.1.4",
"@elrondnetwork/erdjs-walletcore": "1.0.0",
"@elrondnetwork/erdjs-network-providers": "1.0.0",
"@elrondnetwork/erdjs-walletcore": "2.0.0",
"@types/assert": "1.4.6",
"@types/chai": "4.2.11",
"@types/mocha": "9.1.0",
Expand Down
7 changes: 6 additions & 1 deletion src/proto/serializer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe("serialize transactions", () => {
let transaction = new Transaction({
nonce: 89,
value: 0,
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasLimit: 50000,
chainID: "local-testnet"
Expand All @@ -35,6 +36,7 @@ describe("serialize transactions", () => {
let transaction = new Transaction({
nonce: 90,
value: 0,
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasLimit: 80000,
data: new TransactionPayload("hello"),
Expand All @@ -51,6 +53,7 @@ describe("serialize transactions", () => {
let transaction = new Transaction({
nonce: 91,
value: TokenPayment.egldFromAmount(10),
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasLimit: 100000,
data: new TransactionPayload("for the book"),
Expand All @@ -67,13 +70,14 @@ describe("serialize transactions", () => {
let transaction = new Transaction({
nonce: 92,
value: new BigNumber("123456789000000000000000000000"),
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasLimit: 100000,
data: new TransactionPayload("for the spaceship"),
chainID: "local-testnet"
});

transaction.applySignature(new Signature("39938d15812708475dfc8125b5d41dbcea0b2e3e7aabbbfceb6ce4f070de3033676a218b73facd88b1432d7d4accab89c6130b3abe5cc7bbbb5146e61d355b03"), wallets.alice.address)
transaction.applySignature(new Signature("39938d15812708475dfc8125b5d41dbcea0b2e3e7aabbbfceb6ce4f070de3033676a218b73facd88b1432d7d4accab89c6130b3abe5cc7bbbb5146e61d355b03"), wallets.alice.address);

let buffer = serializer.serializeTransaction(transaction);
assert.equal(buffer.toString("hex"), "085c120e00018ee90ff6181f3761632000001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340a08d064a11666f722074686520737061636573686970520d6c6f63616c2d746573746e65745801624039938d15812708475dfc8125b5d41dbcea0b2e3e7aabbbfceb6ce4f070de3033676a218b73facd88b1432d7d4accab89c6130b3abe5cc7bbbb5146e61d355b03");
Expand All @@ -83,6 +87,7 @@ describe("serialize transactions", () => {
let transaction = new Transaction({
nonce: 0,
value: new BigNumber("0"),
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasLimit: 80000,
data: new TransactionPayload("hello"),
Expand Down
2 changes: 2 additions & 0 deletions src/relayedTransactionV2Builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("test relayed v2 transaction builder", function () {

const innerTx = new Transaction({
nonce: 15,
sender: alice.address,
receiver: Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"),
gasLimit: 10,
chainID: networkConfig.ChainID,
Expand All @@ -53,6 +54,7 @@ describe("test relayed v2 transaction builder", function () {

const innerTx = new Transaction({
nonce: 15,
sender: alice.address,
receiver: Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"),
gasLimit: 0,
chainID: networkConfig.ChainID,
Expand Down
1 change: 1 addition & 0 deletions src/relayedTransactionV2Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class RelayedTransactionV2Builder {
.build();

return new Transaction({
sender: this.innerTransaction.getSender(),
receiver: this.innerTransaction.getSender(),
value: 0,
gasLimit:
Expand Down
3 changes: 3 additions & 0 deletions src/smartcontracts/smartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class SmartContract implements ISmartContract {

let transaction = new Transaction({
receiver: Address.Zero(),
sender: Address.Zero(),
value: value,
gasLimit: gasLimit,
gasPrice: gasPrice,
Expand Down Expand Up @@ -147,6 +148,7 @@ export class SmartContract implements ISmartContract {
.build();

let transaction = new Transaction({
sender: Address.Zero(),
receiver: this.getAddress(),
value: value,
gasLimit: gasLimit,
Expand All @@ -173,6 +175,7 @@ export class SmartContract implements ISmartContract {
.build();

let transaction = new Transaction({
sender: Address.Zero(),
receiver: receiver ? receiver : this.getAddress(),
value: value,
gasLimit: gasLimit,
Expand Down
10 changes: 10 additions & 0 deletions src/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 89,
value: "0",
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: minGasLimit,
Expand All @@ -35,6 +36,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 90,
value: "0",
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: 80000,
Expand All @@ -51,6 +53,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 89,
value: "0",
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: minGasLimit,
Expand All @@ -68,6 +71,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 91,
value: TokenPayment.egldFromAmount(10),
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: 100000,
Expand All @@ -84,6 +88,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 92,
value: TokenPayment.egldFromBigInteger("123456789000000000000000000000"),
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: 100000,
Expand All @@ -100,6 +105,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 0,
value: 0,
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: 80000,
Expand All @@ -117,6 +123,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 89,
value: 0,
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: minGasLimit,
Expand All @@ -135,6 +142,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 92,
value: TokenPayment.egldFromBigInteger("123456789000000000000000000000"),
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: 500,
gasLimit: 20,
Expand All @@ -156,6 +164,7 @@ describe("test transaction construction", async () => {
let transaction = new Transaction({
nonce: 92,
value: TokenPayment.egldFromBigInteger("123456789000000000000000000000"),
sender: wallets.alice.address,
receiver: wallets.bob.address,
data: new TransactionPayload("testdata"),
gasPrice: 500,
Expand All @@ -179,6 +188,7 @@ describe("test transaction construction", async () => {
const transaction = new Transaction({
nonce: 90,
value: new BigNumber("1000000000000000000"),
sender: wallets.alice.address,
receiver: wallets.bob.address,
gasPrice: minGasPrice,
gasLimit: 80000,
Expand Down
5 changes: 3 additions & 2 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Transaction {
nonce?: INonce;
value?: ITransactionValue;
receiver: IAddress;
sender?: IAddress;
sender: IAddress;
gasPrice?: IGasPrice;
gasLimit: IGasLimit;
data?: ITransactionPayload;
Expand All @@ -109,7 +109,7 @@ export class Transaction {
}) {
this.nonce = nonce || 0;
this.value = value || 0;
this.sender = sender || Address.Zero();
this.sender = sender;
this.receiver = receiver;
this.gasPrice = gasPrice || TRANSACTION_MIN_GAS_PRICE;
this.gasLimit = gasLimit;
Expand Down Expand Up @@ -244,6 +244,7 @@ export class Transaction {
nonce: Number(plainObjectTransaction.nonce),
value: new BigNumber(plainObjectTransaction.value),
receiver: Address.fromString(plainObjectTransaction.receiver),
sender: Address.fromString(plainObjectTransaction.sender),
gasPrice: Number(plainObjectTransaction.gasPrice),
gasLimit: Number(plainObjectTransaction.gasLimit),
data: new TransactionPayload(Buffer.from(plainObjectTransaction.data || "", "base64")),
Expand Down
5 changes: 3 additions & 2 deletions src/transactionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAddress, IChainID, IGasLimit, IGasPrice, INonce, ITokenPayment, ITransactionPayload, ITransactionValue } from "./interface";
import { ESDTNFTTransferPayloadBuilder, ESDTTransferPayloadBuilder, MultiESDTNFTTransferPayloadBuilder } from "./tokenTransferBuilders";
import { Transaction } from "./transaction";
import {Address} from "./address";

interface IGasEstimator {
forEGLDTransfer(dataLength: number): number;
Expand Down Expand Up @@ -33,7 +34,7 @@ export class TransactionFactory {
nonce: args.nonce,
value: args.value,
receiver: args.receiver,
sender: args.sender,
sender: args.sender || Address.Zero(),
gasPrice: args.gasPrice,
gasLimit: args.gasLimit || estimatedGasLimit,
data: args.data,
Expand All @@ -60,7 +61,7 @@ export class TransactionFactory {
return new Transaction({
nonce: args.nonce,
receiver: args.receiver,
sender: args.sender,
sender: args.sender || Address.Zero(),
gasPrice: args.gasPrice,
gasLimit: args.gasLimit || estimatedGasLimit,
data: transactionPayload,
Expand Down

0 comments on commit 2d0a737

Please sign in to comment.