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

feat: Add BigInt serialization #228

Merged
merged 14 commits into from
Sep 27, 2022
Merged
Prev Previous commit
Next Next commit
chore: Fix ESLint warnings
Add exports to class declarations
Remove unused variables
Fix `any` types
Fix `moduleResolution` in examples
Format `jsconfig.json` `includes` entry for CLI
petarvujovic98 committed Sep 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b6a3866e62621352cc0776447af6d8870883abbd
2 changes: 1 addition & 1 deletion examples/src/clean-state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NearBindgen, call, view, near } from "near-sdk-js";

@NearBindgen({})
class CleanState {
export class CleanState {
@call({})
clean({ keys }) {
keys.forEach((key) => near.storageRemove(key));
4 changes: 2 additions & 2 deletions examples/src/counter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NearBindgen, near, call, view, initialize } from "near-sdk-js";
import { NearBindgen, near, call, view } from "near-sdk-js";
import { isUndefined } from "lodash-es";

@NearBindgen({})
class Counter {
export class Counter {
constructor() {
this.count = 0;
}
4 changes: 2 additions & 2 deletions examples/src/counter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NearBindgen, near, call, view, initialize } from "near-sdk-js";
import { NearBindgen, near, call, view } from "near-sdk-js";
import { isUndefined } from "lodash-es";
import { log } from "./log";

@NearBindgen({})
class Counter {
export class Counter {
count = 0;

@call({})
2 changes: 1 addition & 1 deletion examples/src/cross-contract-call.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NearBindgen, call, view, initialize, near, bytes } from "near-sdk-js";

@NearBindgen({ requireInit: true })
class OnCall {
export class OnCall {
constructor() {
this.personOnCall = "";
this.statusMessageContract = "";
2 changes: 1 addition & 1 deletion examples/src/fungible-token-helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NearBindgen, call, view } from "near-sdk-js";

@NearBindgen({})
class FungibleTokenHelper {
export class FungibleTokenHelper {
constructor() {
this.data = "";
}
2 changes: 1 addition & 1 deletion examples/src/fungible-token-lockable.js
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class Account {
}

@NearBindgen({ initRequired: true })
class LockableFungibleToken {
export class LockableFungibleToken {
constructor() {
this.accounts = new LookupMap("a"); // Account ID -> Account mapping
this.totalSupply = 0; // Total supply of the all tokens
4 changes: 2 additions & 2 deletions examples/src/fungible-token.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import {
} from "near-sdk-js";

@NearBindgen({ initRequired: true })
class FungibleToken {
export class FungibleToken {
constructor() {
this.accounts = new LookupMap("a");
this.totalSupply = 0;
@@ -40,7 +40,7 @@ class FungibleToken {
this.totalSupply = newSupply.toString();
}

internalTransfer({ senderId, receiverId, amount, memo }) {
internalTransfer({ senderId, receiverId, amount, memo: _ }) {
assert(senderId != receiverId, "Sender and receiver should be different");
let amountInt = BigInt(amount);
assert(amountInt > 0n, "The amount should be a positive number");
2 changes: 1 addition & 1 deletion examples/src/log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { near } from "near-sdk-js";

export function log(msg: any) {
export function log(msg: unknown) {
near.log(msg);
}
2 changes: 1 addition & 1 deletion examples/src/non-fungible-token-receiver.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NearBindgen, call, near, assert, initialize } from "near-sdk-js";

@NearBindgen({ requireInit: true })
class NftContract {
export class NftContract {
constructor() {
this.nonFungibleTokenAccountId = "";
}
12 changes: 9 additions & 3 deletions examples/src/non-fungible-token.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class Token {
}

@NearBindgen({ requireInit: true })
class NftContract {
export class NftContract {
constructor() {
this.owner_id = "";
this.owner_by_id = new LookupMap("a");
@@ -29,7 +29,13 @@ class NftContract {
this.owner_by_id = new LookupMap(owner_by_id_prefix);
}

internalTransfer({ sender_id, receiver_id, token_id, approval_id, memo }) {
internalTransfer({
sender_id,
receiver_id,
token_id,
approval_id: _ai,
memo: _m,
}) {
let owner_id = this.owner_by_id.get(token_id);

assert(owner_id !== null, "Token not found");
@@ -125,7 +131,7 @@ class NftContract {
}

@call({})
nftMint({ token_id, token_owner_id, token_metadata }) {
nftMint({ token_id, token_owner_id, token_metadata: _ }) {
let sender_id = near.predecessorAccountId();
assert(sender_id === this.owner_id, "Unauthorized");
assert(this.owner_by_id.get(token_id) === null, "Token ID must be unique");
3 changes: 2 additions & 1 deletion examples/src/parking-lot.ts
Original file line number Diff line number Diff line change
@@ -31,8 +31,9 @@ class Engine {
}

@NearBindgen({})
class ParkingLot {
export class ParkingLot {
cars: LookupMap<CarSpecs>;

constructor() {
this.cars = new LookupMap<CarSpecs>("a");
}
2 changes: 1 addition & 1 deletion examples/src/status-message-collections.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import {
} from "near-sdk-js";

@NearBindgen({})
class StatusMessage {
export class StatusMessage {
constructor() {
this.records = new UnorderedMap("a");
this.uniqueValues = new LookupSet("b");
2 changes: 1 addition & 1 deletion examples/src/status-message.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NearBindgen, call, view, near } from "near-sdk-js";

@NearBindgen({})
class StatusMessage {
export class StatusMessage {
constructor() {
this.records = {};
}
1 change: 1 addition & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
"compilerOptions": {
"experimentalDecorators": true,
"target": "es2020",
"moduleResolution": "node",
"noEmit": true
},
"exclude": ["node_modules"]
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"exclude": ["node_modules"],
"include": ["cli/*.js"]
"include": ["cli"]
}
2 changes: 1 addition & 1 deletion tests/__tests__/test_promise_api.ava.js
Original file line number Diff line number Diff line change
@@ -287,7 +287,7 @@ test("promise delete account", async (t) => {
});

test("promise batch function call weight", async (t) => {
const { ali, caller2Contract, calleeContract } = t.context.accounts;
const { ali, caller2Contract } = t.context.accounts;
let r = await ali.callRaw(
caller2Contract,
"test_promise_batch_call_weight",
4 changes: 2 additions & 2 deletions tests/src/bigint-serialization.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { near, NearBindgen, call, view, initialize } from "near-sdk-js";
import { near, NearBindgen, call, view } from "near-sdk-js";

@NearBindgen({})
class BigIntSerializationTest {
export class BigIntSerializationTest {
bigintField: bigint;

constructor() {
2 changes: 1 addition & 1 deletion tests/src/decorators/payable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { near, NearBindgen, call, view } from "near-sdk-js";

@NearBindgen({})
class PayableTest {
export class PayableTest {
value: string;

constructor() {
2 changes: 1 addition & 1 deletion tests/src/decorators/private.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { near, NearBindgen, call, view } from "near-sdk-js";

@NearBindgen({})
class PrivateTest {
export class PrivateTest {
value: string;

constructor() {
2 changes: 1 addition & 1 deletion tests/src/decorators/require_init_false.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { near, NearBindgen, call, view, initialize } from "near-sdk-js";

@NearBindgen({ requireInit: false })
class NBTest {
export class NBTest {
status: string;

constructor() {
2 changes: 1 addition & 1 deletion tests/src/decorators/require_init_true.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { near, NearBindgen, call, view, initialize } from "near-sdk-js";

@NearBindgen({ requireInit: true })
class NBTest {
export class NBTest {
status: string;

constructor() {
2 changes: 1 addition & 1 deletion tests/src/function-params.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { NearBindgen, call, view, near } from "near-sdk-js";
* Simple contract to test function parameters
*/
@NearBindgen({})
class FunctionParamsTestContract {
export class FunctionParamsTestContract {
constructor() {
this.val1 = "default1";
this.val2 = "default2";
4 changes: 2 additions & 2 deletions tests/src/highlevel-promise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NearBindgen, call, view, NearPromise, near, bytes } from "near-sdk-js";
import { NearBindgen, call, NearPromise, near, bytes } from "near-sdk-js";
import { PublicKey } from "near-sdk-js/lib/types";

function callingData() {
@@ -15,7 +15,7 @@ function arrayN(n) {
}

@NearBindgen({})
class HighlevelPromiseContract {
export class HighlevelPromiseContract {
@call({})
test_promise_batch_stake() {
let promise = NearPromise.new("highlevel-promise.test.near").stake(
2 changes: 1 addition & 1 deletion tests/src/lookup-map.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { NearBindgen, call, view, LookupMap } from "near-sdk-js";
import { House, Room } from "./model.js";

@NearBindgen({})
class LookupMapTestContract {
export class LookupMapTestContract {
constructor() {
this.lookupMap = new LookupMap("a");
}
2 changes: 1 addition & 1 deletion tests/src/lookup-set.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { NearBindgen, call, view, LookupSet } from "near-sdk-js";
import { House, Room } from "./model.js";

@NearBindgen({})
class LookupSetTestContract {
export class LookupSetTestContract {
constructor() {
this.lookupSet = new LookupSet("a");
}
2 changes: 1 addition & 1 deletion tests/src/public-key.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { near, bytes, types } from "near-sdk-js";
import { near, bytes } from "near-sdk-js";
import { CurveType, PublicKey } from "near-sdk-js/lib/types";
import { assert } from "near-sdk-js/lib/utils";

2 changes: 1 addition & 1 deletion tests/src/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NearBindgen, view } from "near-sdk-js";

@NearBindgen({})
class TypeScriptTestContract {
export class TypeScriptTestContract {
@view({})
bigint() {
// JSON.stringify cannot seriaize a BigInt, need manually toString
4 changes: 2 additions & 2 deletions tests/src/unordered-map.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NearBindgen, call, view, UnorderedMap, near } from "near-sdk-js";
import { NearBindgen, call, view, UnorderedMap } from "near-sdk-js";
import { House, Room } from "./model.js";

@NearBindgen({})
class UnorderedMapTestContract {
export class UnorderedMapTestContract {
constructor() {
this.unorderedMap = new UnorderedMap("a");
}
2 changes: 1 addition & 1 deletion tests/src/unordered-set.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { NearBindgen, call, view, UnorderedSet } from "near-sdk-js";
import { House, Room } from "./model.js";

@NearBindgen({})
class UnorderedSetTestContract {
export class UnorderedSetTestContract {
constructor() {
this.unorderedSet = new UnorderedSet("a");
}
2 changes: 1 addition & 1 deletion tests/src/vector.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { NearBindgen, call, view, Vector } from "near-sdk-js";
import { House, Room } from "./model.js";

@NearBindgen({})
class VectorTestContract {
export class VectorTestContract {
constructor() {
this.vector = new Vector("a");
}