From 7e125133776efd643d3de0b22c209aad2fd7506b Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Mon, 13 Aug 2018 18:38:30 +0900 Subject: [PATCH 1/3] Make Parcel and Transaction in RPC use PlatformAddress --- examples/set-regular-key.js | 2 +- integration_tests/Rpc.spec.ts | 2 +- integration_tests/SignedParcel.spec.ts | 2 +- integration_tests/sendSignedParcel.spec.ts | 2 +- integration_tests/setRegularKey.spec.ts | 3 +- integration_tests/useRegistrar.spec.ts | 4 +-- src/core/AssetScheme.ts | 9 +++-- src/core/Parcel.ts | 4 +-- src/core/__test__/Block.spec.ts | 8 ++--- src/core/__test__/Parcel.spec.ts | 4 +-- src/core/__test__/SignedParcel.spec.ts | 11 +++--- src/core/action/Action.ts | 8 ++--- src/core/action/ChangeShardOwners.ts | 8 ++--- src/core/action/ChangeShardUsers.ts | 8 ++--- src/core/action/Payment.ts | 8 ++--- .../action/__test__/ChangeShardOwners.spec.ts | 4 +-- .../action/__test__/ChangeShardUsers.spec.ts | 4 +-- src/core/index.ts | 34 +++++++++---------- src/core/transaction/AssetMintTransaction.ts | 13 ++++--- .../transaction/CreateWorldTransaction.ts | 8 ++--- .../transaction/SetWorldOwnersTransaction.ts | 6 ++-- .../transaction/SetWorldUsersTransaction.ts | 6 ++-- .../__test__/CreateWorldTransaction.spec.ts | 6 ++-- .../SetWorldOwnersTransaction.spec.ts | 6 ++-- .../__test__/SetWorldUsersTransaction.spec.ts | 6 ++-- 25 files changed, 87 insertions(+), 89 deletions(-) diff --git a/examples/set-regular-key.js b/examples/set-regular-key.js index 0171df28..32cf48a5 100644 --- a/examples/set-regular-key.js +++ b/examples/set-regular-key.js @@ -28,7 +28,7 @@ const regularPublic = SDK.util.getPublicFromPrivate(regularSecret); const nonce2 = await sdk.rpc.chain.getNonce(masterAddress); const p2 = sdk.core.createPaymentParcel({ - recipient: masterAddress, + recipient: sdk.key.classes.PlatformAddress.fromAccountId(masterAddress), amount: 10, }); // We can sign a parcel with our `regularSecret`. diff --git a/integration_tests/Rpc.spec.ts b/integration_tests/Rpc.spec.ts index d4029eef..62c0c742 100644 --- a/integration_tests/Rpc.spec.ts +++ b/integration_tests/Rpc.spec.ts @@ -72,7 +72,7 @@ describe("rpc", () => { beforeAll(async () => { const parcel = sdk.core.createPaymentParcel({ - recipient: signerAccount, + recipient: sdk.key.classes.PlatformAddress.fromAccountId(signerAccount), amount: 10, }); const signedParcel = parcel.sign({ diff --git a/integration_tests/SignedParcel.spec.ts b/integration_tests/SignedParcel.spec.ts index d15dd2fa..04bdb9bc 100644 --- a/integration_tests/SignedParcel.spec.ts +++ b/integration_tests/SignedParcel.spec.ts @@ -7,7 +7,7 @@ test("getSignerAccountId", async () => { const nonce = await sdk.rpc.chain.getNonce(accountId); const parcelToSend = sdk.core.createPaymentParcel({ amount: 10, - recipient: accountId, + recipient: sdk.key.classes.PlatformAddress.fromAccountId(accountId), }).sign({ secret, fee: 10, diff --git a/integration_tests/sendSignedParcel.spec.ts b/integration_tests/sendSignedParcel.spec.ts index 632339a0..39e28845 100644 --- a/integration_tests/sendSignedParcel.spec.ts +++ b/integration_tests/sendSignedParcel.spec.ts @@ -8,7 +8,7 @@ const address = SDK.util.getAccountIdFromPrivate(secret); test("sendSignedParcel", async () => { const nonce = await sdk.rpc.chain.getNonce(address); const p = sdk.core.createPaymentParcel({ - recipient: address, + recipient: sdk.key.classes.PlatformAddress.fromAccountId(address), amount: 0, }); const hash = await sdk.rpc.chain.sendSignedParcel(p.sign({ diff --git a/integration_tests/setRegularKey.spec.ts b/integration_tests/setRegularKey.spec.ts index 27e64276..a80f36ea 100644 --- a/integration_tests/setRegularKey.spec.ts +++ b/integration_tests/setRegularKey.spec.ts @@ -1,4 +1,5 @@ import { SDK } from "../"; + const U256 = SDK.Core.classes.U256; const SERVER_URL = process.env.CODECHAIN_RPC_HTTP || "http://localhost:8080"; @@ -29,7 +30,7 @@ test("setRegularKey", async () => { const nonce2 = await sdk.rpc.chain.getNonce(masterAddress); const p2 = sdk.core.createPaymentParcel({ - recipient: masterAddress, + recipient: sdk.key.classes.PlatformAddress.fromAccountId(masterAddress), amount: 10, }); const hash2 = await sdk.rpc.chain.sendSignedParcel(p2.sign({ diff --git a/integration_tests/useRegistrar.spec.ts b/integration_tests/useRegistrar.spec.ts index 167ec179..3308c4f9 100644 --- a/integration_tests/useRegistrar.spec.ts +++ b/integration_tests/useRegistrar.spec.ts @@ -44,7 +44,7 @@ async function setRegularKey() { async function sendCCCToOther() { const nonce = await sdk.rpc.chain.getNonce(masterAddress); const p = sdk.core.createPaymentParcel({ - recipient: otherAddress, + recipient: sdk.key.classes.PlatformAddress.fromAccountId(otherAddress), amount: 100, }); const hash = await sdk.rpc.chain.sendSignedParcel(p.sign({ @@ -67,7 +67,7 @@ async function mintAssetUsingMaster(p2pkh, aliceAddress, bobAddress) { icon_url: "https://gold.image/", }), amount: 10000, - registrar: masterAddress, + registrar: sdk.key.classes.PlatformAddress.fromAccountId(masterAddress), }); const mintTx = sdk.core.createAssetMintTransaction({ diff --git a/src/core/AssetScheme.ts b/src/core/AssetScheme.ts index e4695bdc..8c0587cc 100644 --- a/src/core/AssetScheme.ts +++ b/src/core/AssetScheme.ts @@ -2,7 +2,6 @@ import { AssetTransferAddress } from "../key/AssetTransferAddress"; import { PlatformAddress } from "../key/classes"; -import { H160 } from "./H160"; import { AssetMintTransaction } from "./transaction/AssetMintTransaction"; type NetworkId = string; @@ -13,7 +12,7 @@ export type AssetSchemeData = { worldId: number; metadata: string; amount: number; - registrar: PlatformAddress | H160 | string | null; + registrar: PlatformAddress | null; }; /** * Object that contains information about the Asset when performing AssetMintTransaction. @@ -24,14 +23,14 @@ export class AssetScheme { worldId: number; metadata: string; amount: number; - registrar: H160 | null; + registrar: PlatformAddress | null; constructor(data: AssetSchemeData) { this.networkId = data.networkId; this.shardId = data.shardId; this.worldId = data.worldId; this.metadata = data.metadata; - this.registrar = data.registrar === null ? null : PlatformAddress.ensureAccount(data.registrar); + this.registrar = data.registrar; this.amount = data.amount; } @@ -45,7 +44,7 @@ export class AssetScheme { networkId, metadata, amount, - registrar: registrar === null ? null : registrar.value + registrar: registrar === null ? null : registrar.toString() }; } diff --git a/src/core/Parcel.ts b/src/core/Parcel.ts index 7f7c1c3b..57635da0 100644 --- a/src/core/Parcel.ts +++ b/src/core/Parcel.ts @@ -1,5 +1,5 @@ +import { PlatformAddress } from "../key/PlatformAddress"; import { U256 } from "./U256"; -import { H160 } from "./H160"; import { H256 } from "./H256"; import { H512 } from "./H512"; import { SignedParcel } from "./SignedParcel"; @@ -35,7 +35,7 @@ export class Parcel { return new Parcel(networkId, action); } - static payment(networkId: NetworkId, receiver: H160, value: U256): Parcel { + static payment(networkId: NetworkId, receiver: PlatformAddress, value: U256): Parcel { const action = new Payment(receiver, value); return new Parcel(networkId, action); } diff --git a/src/core/__test__/Block.spec.ts b/src/core/__test__/Block.spec.ts index 93cf2f38..3630755a 100644 --- a/src/core/__test__/Block.spec.ts +++ b/src/core/__test__/Block.spec.ts @@ -1,14 +1,14 @@ import { Block } from "../Block"; import { H256 } from "../H256"; -import { H160 } from "../H160"; import { U256 } from "../U256"; import { Parcel } from "../Parcel"; +import { PlatformAddress } from "../../key/PlatformAddress"; import { getAccountIdFromPrivate } from "../../utils"; test("toJSON", () => { const secret = new H256("ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"); - const sender = new H160(getAccountIdFromPrivate(secret.value)); - const p = Parcel.payment("tc", new H160("0x2222222222222222222222222222222222222222"), new U256(11)).sign({ + const sender = PlatformAddress.fromAccountId(getAccountIdFromPrivate(secret.value)); + const p = Parcel.payment("tc", PlatformAddress.fromAccountId("0x2222222222222222222222222222222222222222"), new U256(11)).sign({ secret, fee: 33, nonce: 44 @@ -17,7 +17,7 @@ test("toJSON", () => { parentHash: new H256("0000000000000000000000000000000000000000000000000000000000000000"), timestamp: 1, number: 2, - author: new H160("1111111111111111111111111111111111111111"), + author: PlatformAddress.fromAccountId("1111111111111111111111111111111111111111").getAccountId(), extraData: Buffer.from([]), parcelsRoot: new H256("1111111111111111111111111111111111111111111111111111111111111111"), stateRoot: new H256("2222222222222222222222222222222222222222222222222222222222222222"), diff --git a/src/core/__test__/Parcel.spec.ts b/src/core/__test__/Parcel.spec.ts index 5b02f73c..0c4c90e2 100644 --- a/src/core/__test__/Parcel.spec.ts +++ b/src/core/__test__/Parcel.spec.ts @@ -1,7 +1,7 @@ -import { H160 } from "../H160"; import { H256 } from "../H256"; import { U256 } from "../U256"; import { Parcel } from "../Parcel"; +import { PlatformAddress } from "../../key/PlatformAddress"; test("rlp", () => { const t = Parcel.transactions("tc"); @@ -42,7 +42,7 @@ test("signed hash", () => { }); test("toJSON", () => { - const p = Parcel.payment("tc", new H160("0x0000000000000000000000000000000000000000"), new U256(11)); + const p = Parcel.payment("tc", PlatformAddress.fromAccountId("0x0000000000000000000000000000000000000000"), new U256(11)); p.setFee(33); p.setNonce(44); expect(Parcel.fromJSON(p.toJSON())).toEqual(p); diff --git a/src/core/__test__/SignedParcel.spec.ts b/src/core/__test__/SignedParcel.spec.ts index b7d3abd7..7d2ffc3b 100644 --- a/src/core/__test__/SignedParcel.spec.ts +++ b/src/core/__test__/SignedParcel.spec.ts @@ -1,6 +1,5 @@ import { PlatformAddress } from "../../key/classes"; -import { H160 } from "../H160"; import { H256 } from "../H256"; import { U256 } from "../U256"; import { Parcel } from "../Parcel"; @@ -9,7 +8,7 @@ import { getAccountIdFromPrivate } from "../../utils"; test("toJSON", () => { const secret = new H256("ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"); - const p = Parcel.payment("tc", new H160("0x0000000000000000000000000000000000000000"), new U256(11)).sign({ + const p = Parcel.payment("tc", PlatformAddress.fromAccountId("0x0000000000000000000000000000000000000000"), new U256(11)).sign({ secret, fee: 33, nonce: 33 @@ -19,8 +18,8 @@ test("toJSON", () => { test("getSignerAccountId", () => { const secret = new H256("ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"); - const signerAccountId = new H160(getAccountIdFromPrivate(secret.value)); - const p = Parcel.payment("tc", new H160("0x0000000000000000000000000000000000000000"), new U256(11)).sign({ + const signerAccountId = PlatformAddress.fromAccountId(getAccountIdFromPrivate(secret.value)).getAccountId(); + const p = Parcel.payment("tc", PlatformAddress.fromAccountId("0x0000000000000000000000000000000000000000"), new U256(11)).sign({ secret, fee: 33, nonce: 44 @@ -30,9 +29,9 @@ test("getSignerAccountId", () => { test("getSignerAddress", () => { const secret = new H256("ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"); - const signerAccountId = new H160(getAccountIdFromPrivate(secret.value)); + const signerAccountId = PlatformAddress.fromAccountId(getAccountIdFromPrivate(secret.value)).getAccountId(); const signerAddress = PlatformAddress.fromAccountId(signerAccountId); - const p = Parcel.payment("tc", new H160("0x0000000000000000000000000000000000000000"), new U256(11)).sign({ + const p = Parcel.payment("tc", PlatformAddress.fromAccountId("0x0000000000000000000000000000000000000000"), new U256(11)).sign({ secret, fee: 33, nonce: 44 diff --git a/src/core/action/Action.ts b/src/core/action/Action.ts index eb4691ca..747ca20c 100644 --- a/src/core/action/Action.ts +++ b/src/core/action/Action.ts @@ -1,5 +1,5 @@ +import { PlatformAddress } from "../../key/PlatformAddress"; import { getTransactionFromJSON } from "../transaction/Transaction"; -import { H160 } from "../H160"; import { U256 } from "../U256"; import { H512 } from "../H512"; @@ -20,7 +20,7 @@ export function getActionFromJSON(json: any): Action { return new ChangeShardState({ transactions: transactions.map(getTransactionFromJSON) }); case "payment": const { receiver, amount } = json; - return new Payment(new H160(receiver), new U256(amount)); + return new Payment(PlatformAddress.ensure(receiver), new U256(amount)); case "setRegularKey": const { key } = json; return new SetRegularKey(new H512(key)); @@ -28,10 +28,10 @@ export function getActionFromJSON(json: any): Action { return new CreateShard(); case "changeShardOwners": const { shardId, owners } = json; - return new ChangeShardOwners({ shardId, owners: owners.map(H160.ensure) }); + return new ChangeShardOwners({ shardId, owners: owners.map(PlatformAddress.ensure) }); case "changeShardUsers": { const { shardId, users } = json; - return new ChangeShardUsers({ shardId, users: users.map(H160.ensure) }); + return new ChangeShardUsers({ shardId, users: users.map(PlatformAddress.ensure) }); } default: throw new Error(`Unexpected parcel action: ${action}`); diff --git a/src/core/action/ChangeShardOwners.ts b/src/core/action/ChangeShardOwners.ts index 6c07f02f..45a71cce 100644 --- a/src/core/action/ChangeShardOwners.ts +++ b/src/core/action/ChangeShardOwners.ts @@ -1,9 +1,9 @@ -import { H160 } from "../H160"; +import { PlatformAddress } from "../../key/PlatformAddress"; export class ChangeShardOwners { public readonly shardId: number; - public readonly owners: H160[]; - constructor(params: { shardId: number, owners: H160[] }) { + public readonly owners: PlatformAddress[]; + constructor(params: { shardId: number, owners: PlatformAddress[] }) { const { shardId, owners } = params; this.shardId = shardId; this.owners = owners; @@ -11,7 +11,7 @@ export class ChangeShardOwners { toEncodeObject(): Array { const { shardId, owners } = this; - return [5, shardId, owners.map(owner => owner.toEncodeObject())]; + return [5, shardId, owners.map(owner => owner.getAccountId().toEncodeObject())]; } toJSON() { diff --git a/src/core/action/ChangeShardUsers.ts b/src/core/action/ChangeShardUsers.ts index 64591539..504c0d81 100644 --- a/src/core/action/ChangeShardUsers.ts +++ b/src/core/action/ChangeShardUsers.ts @@ -1,9 +1,9 @@ -import { H160 } from "../H160"; +import { PlatformAddress } from "../../key/PlatformAddress"; export class ChangeShardUsers { public readonly shardId: number; - public readonly users: H160[]; - constructor(params: { shardId: number, users: H160[] }) { + public readonly users: PlatformAddress[]; + constructor(params: { shardId: number, users: PlatformAddress[] }) { const { shardId, users } = params; this.shardId = shardId; this.users = users; @@ -11,7 +11,7 @@ export class ChangeShardUsers { toEncodeObject(): Array { const { shardId, users } = this; - return [6, shardId, users.map(user => user.toEncodeObject())]; + return [6, shardId, users.map(user => user.getAccountId().toEncodeObject())]; } toJSON() { diff --git a/src/core/action/Payment.ts b/src/core/action/Payment.ts index 9a8be3ee..bc2545be 100644 --- a/src/core/action/Payment.ts +++ b/src/core/action/Payment.ts @@ -1,17 +1,17 @@ -import { H160 } from "../H160"; +import { PlatformAddress } from "../../key/PlatformAddress"; import { U256 } from "../U256"; export class Payment { - receiver: H160; + receiver: PlatformAddress; amount: U256; - constructor(receiver: H160, amount: U256) { + constructor(receiver: PlatformAddress, amount: U256) { this.receiver = receiver; this.amount = amount; } toEncodeObject(): Array { - return [2, this.receiver.toEncodeObject(), this.amount.toEncodeObject()]; + return [2, this.receiver.getAccountId().toEncodeObject(), this.amount.toEncodeObject()]; } toJSON() { diff --git a/src/core/action/__test__/ChangeShardOwners.spec.ts b/src/core/action/__test__/ChangeShardOwners.spec.ts index 2c517c86..9776c5c4 100644 --- a/src/core/action/__test__/ChangeShardOwners.spec.ts +++ b/src/core/action/__test__/ChangeShardOwners.spec.ts @@ -1,12 +1,12 @@ import { ChangeShardOwners } from "../ChangeShardOwners"; -import { H160 } from "../../H160"; +import { PlatformAddress } from "../../../key/PlatformAddress"; import { getActionFromJSON } from "../Action"; describe("ChangeShardOwners", () => { test("getActionFromJSON", () => { const t = new ChangeShardOwners({ shardId: 42, - owners: [H160.ensure("0x0123456789012345678901234567890123456789")] + owners: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")] }); expect(getActionFromJSON(t.toJSON())).toEqual(t); }); diff --git a/src/core/action/__test__/ChangeShardUsers.spec.ts b/src/core/action/__test__/ChangeShardUsers.spec.ts index 896bc472..75ca8a5e 100644 --- a/src/core/action/__test__/ChangeShardUsers.spec.ts +++ b/src/core/action/__test__/ChangeShardUsers.spec.ts @@ -1,12 +1,12 @@ import { ChangeShardUsers } from "../ChangeShardUsers"; -import { H160 } from "../../H160"; +import { PlatformAddress } from "../../../key/PlatformAddress"; import { getActionFromJSON } from "../Action"; describe("ChangeShardUsers", () => { test("getActionFromJSON", () => { const t = new ChangeShardUsers({ shardId: 42, - users: [H160.ensure("0x0123456789012345678901234567890123456789")] + users: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")] }); expect(getActionFromJSON(t.toJSON())).toEqual(t); }); diff --git a/src/core/index.ts b/src/core/index.ts index 77be2e3d..dac27844 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -49,10 +49,10 @@ export class Core { * @throws Given string for recipient is invalid for converting it to H160 * @throws Given number or string for amount is invalid for converting it to U256 */ - createPaymentParcel(params: { recipient: PlatformAddress | H160 | string, amount: U256 | number | string }): Parcel { + createPaymentParcel(params: { recipient: PlatformAddress | string, amount: U256 | number | string }): Parcel { const { recipient, amount } = params; const action = new Payment( - PlatformAddress.ensureAccount(recipient), + PlatformAddress.ensure(recipient), U256.ensure(amount) ); return new Parcel( @@ -100,9 +100,9 @@ export class Core { ); } - createChangeShardOwnersParcel(params: { shardId: number, owners: (H160 | PlatformAddress | string)[] }): Parcel { + createChangeShardOwnersParcel(params: { shardId: number, owners: (PlatformAddress | string)[] }): Parcel { const { shardId, owners } = params; - const action = new ChangeShardOwners({ shardId, owners: owners.map(PlatformAddress.ensureAccount) }); + const action = new ChangeShardOwners({ shardId, owners: owners.map(PlatformAddress.ensure) }); return new Parcel( this.networkId, action @@ -114,9 +114,9 @@ export class Core { * @param params.shardId * @param params.users */ - createChangeShardUsersParcel(params: { shardId: number, users: (H160 | PlatformAddress | string)[] }): Parcel { + createChangeShardUsersParcel(params: { shardId: number, users: (PlatformAddress | string)[] }): Parcel { const { shardId, users } = params; - const action = new ChangeShardUsers({ shardId, users: users.map(PlatformAddress.ensureAccount) }); + const action = new ChangeShardUsers({ shardId, users: users.map(PlatformAddress.ensure) }); return new Parcel( this.networkId, action @@ -131,14 +131,14 @@ export class Core { * @param params.registrar Platform account or null. If account is present, the * parcel that includes AssetTransferTransaction of this asset must be signed by * the registrar account. - * @throws Given string for registrar is invalid for converting it to H160 + * @throws Given string for registrar is invalid for converting it to paltform account */ createAssetScheme(params: { shardId: number, worldId: number, metadata: string, amount: number, - registrar: PlatformAddress | H160 | string | null + registrar: PlatformAddress | string | null }): AssetScheme { const { shardId, worldId, metadata, amount, registrar } = params; return new AssetScheme({ @@ -147,14 +147,14 @@ export class Core { worldId, metadata, amount, - registrar, + registrar: registrar == null ? null : PlatformAddress.ensure(registrar), }); } createCreateWorldTransaction(params: { networkId?: NetworkId; shardId: number, - owners: (H160 | PlatformAddress | string)[], + owners: (PlatformAddress | string)[], nonce?: number, }): CreateWorldTransaction { const { networkId, shardId, owners, nonce } = params; @@ -162,7 +162,7 @@ export class Core { return new CreateWorldTransaction({ networkId: networkId || this.networkId, shardId, - owners: owners.map(PlatformAddress.ensureAccount), + owners: owners.map(PlatformAddress.ensure), nonce: nonce || 0 }); } @@ -171,7 +171,7 @@ export class Core { networkId?: NetworkId; shardId: number, worldId: number, - owners: (H160 | PlatformAddress | string)[], + owners: (PlatformAddress | string)[], nonce: number, }): SetWorldOwnersTransaction { const { networkId, shardId, worldId, owners, nonce } = params; @@ -180,7 +180,7 @@ export class Core { networkId: networkId || this.networkId, shardId, worldId, - owners: owners.map(PlatformAddress.ensureAccount), + owners: owners.map(PlatformAddress.ensure), nonce }); } @@ -189,7 +189,7 @@ export class Core { networkId?: NetworkId; shardId: number, worldId: number, - users: (H160 | PlatformAddress | string)[], + users: (PlatformAddress | string)[], nonce: number, }): SetWorldUsersTransaction { const { networkId, shardId, worldId, users, nonce } = params; @@ -198,7 +198,7 @@ export class Core { networkId: networkId || this.networkId, shardId, worldId, - users: users.map(PlatformAddress.ensureAccount), + users: users.map(PlatformAddress.ensure), nonce }); } @@ -209,7 +209,7 @@ export class Core { shardId: number, worldId: number, metadata: string, - registrar?: PlatformAddress | H160 | string, + registrar?: PlatformAddress | string, amount: number | null, }, recipient: AssetTransferAddress | string, @@ -222,7 +222,7 @@ export class Core { shardId, worldId, nonce: nonce || 0, - registrar: registrar || null, + registrar: registrar == null ? null : PlatformAddress.ensure(registrar), metadata, output: { amount, diff --git a/src/core/transaction/AssetMintTransaction.ts b/src/core/transaction/AssetMintTransaction.ts index 897da9cf..0100efdf 100644 --- a/src/core/transaction/AssetMintTransaction.ts +++ b/src/core/transaction/AssetMintTransaction.ts @@ -2,7 +2,6 @@ import { Buffer } from "buffer"; import { PlatformAddress } from "../../key/classes"; -import { H160 } from "../H160"; import { H256 } from "../H256"; import { blake256, blake256WithKey } from "../../utils"; import { Asset } from "../Asset"; @@ -22,7 +21,7 @@ export type AssetMintTransactionData = { parameters: Buffer[]; amount: number | null; }; - registrar: PlatformAddress | H160 | string | null; + registrar: PlatformAddress | null; nonce: number; }; @@ -50,7 +49,7 @@ export class AssetMintTransaction { parameters: Buffer[]; amount: number | null; }; - readonly registrar: H160 | null; + readonly registrar: PlatformAddress | null; readonly nonce: number; readonly type = "assetMint"; @@ -71,7 +70,7 @@ export class AssetMintTransaction { this.worldId = worldId; this.metadata = metadata; this.output = output; - this.registrar = registrar === null ? null : PlatformAddress.ensureAccount(registrar); + this.registrar = registrar; this.nonce = nonce; } @@ -92,7 +91,7 @@ export class AssetMintTransaction { parameters: parameters.map((p: Array) => Buffer.from(p)), amount: amount === null ? null : amount, }, - registrar: registrar === null ? null : new H160(registrar), + registrar: registrar === null ? null : PlatformAddress.fromString(registrar), nonce, }); } @@ -115,7 +114,7 @@ export class AssetMintTransaction { parameters: parameters.map(parameter => [...parameter]), amount, }, - registrar: registrar === null ? null : registrar.value, + registrar: registrar === null ? null : registrar.toString(), nonce, } }; @@ -135,7 +134,7 @@ export class AssetMintTransaction { lockScriptHash.toEncodeObject(), parameters.map(parameter => Buffer.from(parameter)), amount ? [amount] : [], - registrar ? [registrar.toEncodeObject()] : [], + registrar ? [registrar.getAccountId().toEncodeObject()] : [], nonce ]; } diff --git a/src/core/transaction/CreateWorldTransaction.ts b/src/core/transaction/CreateWorldTransaction.ts index a1b75ff9..bee39c46 100644 --- a/src/core/transaction/CreateWorldTransaction.ts +++ b/src/core/transaction/CreateWorldTransaction.ts @@ -1,4 +1,4 @@ -import { H160 } from "../H160"; +import { PlatformAddress } from "../../key/PlatformAddress"; import { H256 } from "../H256"; import { blake256 } from "../../utils"; @@ -10,7 +10,7 @@ export type CreateWorldData = { networkId: NetworkId; shardId: number; nonce: number; - owners: H160[]; + owners: PlatformAddress[]; }; /** @@ -23,7 +23,7 @@ export class CreateWorldTransaction { readonly networkId: NetworkId; readonly shardId: number; readonly nonce: number; - readonly owners: H160[]; + readonly owners: PlatformAddress[]; readonly type = "createWorld"; @@ -65,7 +65,7 @@ export class CreateWorldTransaction { networkId, shardId, nonce, - owners + owners.map(owner => owner.getAccountId().toEncodeObject()) ]; } diff --git a/src/core/transaction/SetWorldOwnersTransaction.ts b/src/core/transaction/SetWorldOwnersTransaction.ts index b31d0281..0931f784 100644 --- a/src/core/transaction/SetWorldOwnersTransaction.ts +++ b/src/core/transaction/SetWorldOwnersTransaction.ts @@ -1,4 +1,4 @@ -import { H160 } from "../H160"; +import { PlatformAddress } from "../../key/PlatformAddress"; import { H256 } from "../H256"; import { blake256 } from "../../utils"; @@ -11,7 +11,7 @@ export type SetWorldOwnersData = { shardId: number; worldId: number; nonce: number; - owners: H160[]; + owners: PlatformAddress[]; }; /** @@ -22,7 +22,7 @@ export class SetWorldOwnersTransaction { readonly shardId: number; readonly worldId: number; readonly nonce: number; - readonly owners: H160[]; + readonly owners: PlatformAddress[]; readonly type = "setWorldOwners"; diff --git a/src/core/transaction/SetWorldUsersTransaction.ts b/src/core/transaction/SetWorldUsersTransaction.ts index 67172cb4..3b945f61 100644 --- a/src/core/transaction/SetWorldUsersTransaction.ts +++ b/src/core/transaction/SetWorldUsersTransaction.ts @@ -1,4 +1,4 @@ -import { H160 } from "../H160"; +import { PlatformAddress } from "../../key/PlatformAddress"; import { H256 } from "../H256"; import { blake256 } from "../../utils"; @@ -11,7 +11,7 @@ export type SetWorldUsersData = { shardId: number; worldId: number; nonce: number; - users: H160[]; + users: PlatformAddress[]; }; /** @@ -22,7 +22,7 @@ export class SetWorldUsersTransaction { readonly shardId: number; readonly worldId: number; readonly nonce: number; - readonly users: H160[]; + readonly users: PlatformAddress[]; readonly type = "setWorldUsers"; diff --git a/src/core/transaction/__test__/CreateWorldTransaction.spec.ts b/src/core/transaction/__test__/CreateWorldTransaction.spec.ts index 5feb8e6d..d13f69e0 100644 --- a/src/core/transaction/__test__/CreateWorldTransaction.spec.ts +++ b/src/core/transaction/__test__/CreateWorldTransaction.spec.ts @@ -1,13 +1,13 @@ import { CreateWorldTransaction } from "../CreateWorldTransaction"; -import { H160 } from "../../H160"; import { getTransactionFromJSON } from "../Transaction"; +import { PlatformAddress } from "../../../key/classes"; describe("CreateWorldTransaction", () => { test("toJSON", () => { const t = new CreateWorldTransaction({ networkId: "a1", shardId: 2, - owners: [H160.ensure("0x0123456789012345678901234567890123456789")], + owners: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")], nonce: 0, }); expect(CreateWorldTransaction.fromJSON(t.toJSON())).toEqual(t); @@ -17,7 +17,7 @@ describe("CreateWorldTransaction", () => { const t = new CreateWorldTransaction({ networkId: "x1", shardId: 2, - owners: [H160.ensure("0x0123456789012345678901234567890123456789")], + owners: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")], nonce: 0, }); expect(getTransactionFromJSON(t.toJSON())).toEqual(t); diff --git a/src/core/transaction/__test__/SetWorldOwnersTransaction.spec.ts b/src/core/transaction/__test__/SetWorldOwnersTransaction.spec.ts index 0a1e2d2d..7594f0b5 100644 --- a/src/core/transaction/__test__/SetWorldOwnersTransaction.spec.ts +++ b/src/core/transaction/__test__/SetWorldOwnersTransaction.spec.ts @@ -1,6 +1,6 @@ import { SetWorldOwnersTransaction } from "../SetWorldOwnersTransaction"; -import { H160 } from "../../H160"; import { getTransactionFromJSON } from "../Transaction"; +import { PlatformAddress } from "../../../key/classes"; describe("SetWorldOwnersTransaction", () => { test("toJSON", () => { @@ -8,7 +8,7 @@ describe("SetWorldOwnersTransaction", () => { networkId: "x1", shardId: 42, worldId: 0x42, - owners: [H160.ensure("0x0123456789012345678901234567890123456789")], + owners: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")], nonce: 0, }); expect(SetWorldOwnersTransaction.fromJSON(t.toJSON())).toEqual(t); @@ -19,7 +19,7 @@ describe("SetWorldOwnersTransaction", () => { networkId: "1a", shardId: 42, worldId: 0x42, - owners: [H160.ensure("0x0123456789012345678901234567890123456789")], + owners: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")], nonce: 0, }); expect(getTransactionFromJSON(t.toJSON())).toEqual(t); diff --git a/src/core/transaction/__test__/SetWorldUsersTransaction.spec.ts b/src/core/transaction/__test__/SetWorldUsersTransaction.spec.ts index f106a595..7bff09b9 100644 --- a/src/core/transaction/__test__/SetWorldUsersTransaction.spec.ts +++ b/src/core/transaction/__test__/SetWorldUsersTransaction.spec.ts @@ -1,6 +1,6 @@ import { SetWorldUsersTransaction } from "../SetWorldUsersTransaction"; -import { H160 } from "../../H160"; import { getTransactionFromJSON } from "../Transaction"; +import { PlatformAddress } from "../../../key/classes"; describe("SetWorldUsersTransaction", () => { test("toJSON", () => { @@ -8,7 +8,7 @@ describe("SetWorldUsersTransaction", () => { networkId: "12", shardId: 42, worldId: 0x42, - users: [H160.ensure("0x0123456789012345678901234567890123456789")], + users: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")], nonce: 0, }); expect(SetWorldUsersTransaction.fromJSON(t.toJSON())).toEqual(t); @@ -19,7 +19,7 @@ describe("SetWorldUsersTransaction", () => { networkId: "12", shardId: 42, worldId: 0x42, - users: [H160.ensure("0x0123456789012345678901234567890123456789")], + users: [PlatformAddress.fromAccountId("0x0123456789012345678901234567890123456789")], nonce: 0, }); expect(getTransactionFromJSON(t.toJSON())).toEqual(t); From 929efd136016088ba9c2bac5536d65d95c6d3a65 Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Mon, 13 Aug 2018 19:37:19 +0900 Subject: [PATCH 2/3] Make Block in RPC use PlatformAddress --- src/core/Block.ts | 10 +++++----- src/core/__test__/Block.spec.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/Block.ts b/src/core/Block.ts index f1a54ded..3878a8ef 100644 --- a/src/core/Block.ts +++ b/src/core/Block.ts @@ -1,4 +1,4 @@ -import { H160 } from "./H160"; +import { PlatformAddress } from "../key/PlatformAddress"; import { H256 } from "./H256"; import { U256 } from "./U256"; import { SignedParcel } from "./SignedParcel"; @@ -7,7 +7,7 @@ export type BlockData = { parentHash: H256; timestamp: number; number: number; - author: H160; + author: PlatformAddress; extraData: Buffer; parcelsRoot: H256; stateRoot: H256; @@ -24,7 +24,7 @@ export class Block { parentHash: H256; timestamp: number; number: number; - author: H160; + author: PlatformAddress; extraData: Buffer; parcelsRoot: H256; stateRoot: H256; @@ -58,7 +58,7 @@ export class Block { parentHash: new H256(parentHash), timestamp, number, - author: new H160(author), + author: PlatformAddress.fromString(author), extraData, parcelsRoot: new H256(parcelsRoot), stateRoot: new H256(stateRoot), @@ -77,7 +77,7 @@ export class Block { parentHash: parentHash.value, timestamp, number, - author: author.value, + author: author.toString(), extraData, parcelsRoot: parcelsRoot.value, stateRoot: stateRoot.value, diff --git a/src/core/__test__/Block.spec.ts b/src/core/__test__/Block.spec.ts index 3630755a..8b9bf2a6 100644 --- a/src/core/__test__/Block.spec.ts +++ b/src/core/__test__/Block.spec.ts @@ -17,7 +17,7 @@ test("toJSON", () => { parentHash: new H256("0000000000000000000000000000000000000000000000000000000000000000"), timestamp: 1, number: 2, - author: PlatformAddress.fromAccountId("1111111111111111111111111111111111111111").getAccountId(), + author: PlatformAddress.fromAccountId("1111111111111111111111111111111111111111"), extraData: Buffer.from([]), parcelsRoot: new H256("1111111111111111111111111111111111111111111111111111111111111111"), stateRoot: new H256("2222222222222222222222222222222222222222222222222222222222222222"), From 60e9fd406b92f3fe7ea70658be6ce281d1593b87 Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Mon, 13 Aug 2018 19:51:54 +0900 Subject: [PATCH 3/3] Make RPC use PlatformAddress --- examples/set-regular-key.js | 5 +++-- integration_tests/Rpc.spec.ts | 24 +++++++++++++++------- integration_tests/SignedParcel.spec.ts | 5 +++-- integration_tests/helper.ts | 3 ++- integration_tests/sendSignedParcel.spec.ts | 5 +++-- integration_tests/setRegularKey.spec.ts | 5 +++-- integration_tests/useRegistrar.spec.ts | 10 +++++---- src/rpc/chain.ts | 15 +++++++------- 8 files changed, 44 insertions(+), 28 deletions(-) diff --git a/examples/set-regular-key.js b/examples/set-regular-key.js index 32cf48a5..624b0d50 100644 --- a/examples/set-regular-key.js +++ b/examples/set-regular-key.js @@ -2,7 +2,8 @@ const SDK = require("codechain-sdk"); const sdk = new SDK({ server: "http://localhost:8080" }); const masterSecret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; -const masterAddress = SDK.util.getAccountIdFromPrivate(masterSecret); +const masterAccountId = SDK.util.getAccountIdFromPrivate(masterSecret); +const masterAddress = sdk.key.classes.PlatformAddress.fromAccountId(masterAccountId); const regularSecret = SDK.util.generatePrivateKey(); const regularPublic = SDK.util.getPublicFromPrivate(regularSecret); @@ -28,7 +29,7 @@ const regularPublic = SDK.util.getPublicFromPrivate(regularSecret); const nonce2 = await sdk.rpc.chain.getNonce(masterAddress); const p2 = sdk.core.createPaymentParcel({ - recipient: sdk.key.classes.PlatformAddress.fromAccountId(masterAddress), + recipient: masterAddress, amount: 10, }); // We can sign a parcel with our `regularSecret`. diff --git a/integration_tests/Rpc.spec.ts b/integration_tests/Rpc.spec.ts index 62c0c742..9346cecf 100644 --- a/integration_tests/Rpc.spec.ts +++ b/integration_tests/Rpc.spec.ts @@ -9,11 +9,16 @@ describe("rpc", () => { const invalidHash = "0x0000000000000000000000000000000000000000000000000000000000000000"; const signerSecret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; const signerAccount = "0xa6594b7196808d161b6fb137e781abbc251385d9"; + const signerAddress = "cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7"; beforeAll(async () => { sdk = new SDK({ server: "http://localhost:8080" }); }); + test("PlatformAddress", () => { + expect(sdk.key.classes.PlatformAddress.fromAccountId(signerAccount).value).toEqual(signerAddress); + }); + describe("node", () => { test("ping", async () => { expect(await sdk.rpc.node.ping()).toBe("pong"); @@ -50,18 +55,23 @@ describe("rpc", () => { describe("with account", () => { const account = "0xa6594b7196808d161b6fb137e781abbc251385d9"; + const address = "cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7"; + + test("PlatformAddress", () => { + expect(sdk.key.classes.PlatformAddress.fromAccountId(account).value).toEqual(address); + }); test("getBalance", async () => { - expect(await sdk.rpc.chain.getBalance(account)).toEqual(expect.any(U256)); + expect(await sdk.rpc.chain.getBalance(address)).toEqual(expect.any(U256)); }); test("getNonce", async () => { - expect(await sdk.rpc.chain.getNonce(account)).toEqual(expect.any(U256)); + expect(await sdk.rpc.chain.getNonce(address)).toEqual(expect.any(U256)); }); // FIXME: setRegularKey action isn't implemented. test.skip("getRegularKey", async () => { - expect(await sdk.rpc.chain.getRegularKey(account)).toEqual(expect.any(H512)); + expect(await sdk.rpc.chain.getRegularKey(address)).toEqual(expect.any(H512)); }); }); @@ -72,13 +82,13 @@ describe("rpc", () => { beforeAll(async () => { const parcel = sdk.core.createPaymentParcel({ - recipient: sdk.key.classes.PlatformAddress.fromAccountId(signerAccount), + recipient: signerAddress, amount: 10, }); const signedParcel = parcel.sign({ secret: signerSecret, fee: 10, - nonce: await sdk.rpc.chain.getNonce(signerAccount), + nonce: await sdk.rpc.chain.getNonce(signerAddress), }); parcelHash = await sdk.rpc.chain.sendSignedParcel(signedParcel); }); @@ -120,7 +130,7 @@ describe("rpc", () => { }); await sdk.rpc.chain.sendSignedParcel(parcel.sign({ secret: signerSecret, - nonce: await sdk.rpc.chain.getNonce(signerAccount), + nonce: await sdk.rpc.chain.getNonce(signerAddress), fee: 10 })); }); @@ -183,7 +193,7 @@ describe("rpc", () => { const parcel = sdk.core.createChangeShardStateParcel({ transactions: [mintTransaction, transferTransaction] }); await sdk.rpc.chain.sendSignedParcel(parcel.sign({ secret: signerSecret, - nonce: await sdk.rpc.chain.getNonce(signerAccount), + nonce: await sdk.rpc.chain.getNonce(signerAddress), fee: 10 })); blockNumber = await sdk.rpc.chain.getBestBlockNumber(); diff --git a/integration_tests/SignedParcel.spec.ts b/integration_tests/SignedParcel.spec.ts index 04bdb9bc..3dd5a0e4 100644 --- a/integration_tests/SignedParcel.spec.ts +++ b/integration_tests/SignedParcel.spec.ts @@ -4,10 +4,11 @@ test("getSignerAccountId", async () => { const sdk = new SDK({ server: process.env.CODECHAIN_RPC_HTTP || "http://localhost:8080" }); const secret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; const accountId = sdk.util.getAccountIdFromPrivate(secret); - const nonce = await sdk.rpc.chain.getNonce(accountId); + const accountAddress = sdk.key.classes.PlatformAddress.fromAccountId(accountId); + const nonce = await sdk.rpc.chain.getNonce(accountAddress); const parcelToSend = sdk.core.createPaymentParcel({ amount: 10, - recipient: sdk.key.classes.PlatformAddress.fromAccountId(accountId), + recipient: accountAddress, }).sign({ secret, fee: 10, diff --git a/integration_tests/helper.ts b/integration_tests/helper.ts index 2712cc31..afe13bf0 100644 --- a/integration_tests/helper.ts +++ b/integration_tests/helper.ts @@ -4,7 +4,8 @@ const SERVER_URL = process.env.CODECHAIN_RPC_HTTP || "http://localhost:8080"; const sdk = new SDK({ server: SERVER_URL }); const secret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; -const address = sdk.util.getAccountIdFromPrivate(secret); +const accountId = sdk.util.getAccountIdFromPrivate(secret); +const address = sdk.key.classes.PlatformAddress.fromAccountId(accountId); export const sendTransactions = async ({ transactions }) => { const parcel = sdk.core.createChangeShardStateParcel({ diff --git a/integration_tests/sendSignedParcel.spec.ts b/integration_tests/sendSignedParcel.spec.ts index 39e28845..d920d365 100644 --- a/integration_tests/sendSignedParcel.spec.ts +++ b/integration_tests/sendSignedParcel.spec.ts @@ -3,12 +3,13 @@ import { SDK } from "../"; const SERVER_URL = process.env.CODECHAIN_RPC_HTTP || "http://localhost:8080"; const sdk = new SDK({ server: SERVER_URL }); const secret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; -const address = SDK.util.getAccountIdFromPrivate(secret); +const accountId = SDK.util.getAccountIdFromPrivate(secret); +const address = sdk.key.classes.PlatformAddress.fromAccountId(accountId); test("sendSignedParcel", async () => { const nonce = await sdk.rpc.chain.getNonce(address); const p = sdk.core.createPaymentParcel({ - recipient: sdk.key.classes.PlatformAddress.fromAccountId(address), + recipient: address, amount: 0, }); const hash = await sdk.rpc.chain.sendSignedParcel(p.sign({ diff --git a/integration_tests/setRegularKey.spec.ts b/integration_tests/setRegularKey.spec.ts index a80f36ea..004124f9 100644 --- a/integration_tests/setRegularKey.spec.ts +++ b/integration_tests/setRegularKey.spec.ts @@ -5,7 +5,8 @@ const U256 = SDK.Core.classes.U256; const SERVER_URL = process.env.CODECHAIN_RPC_HTTP || "http://localhost:8080"; const sdk = new SDK({ server: SERVER_URL }); const masterSecret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; -const masterAddress = SDK.util.getAccountIdFromPrivate(masterSecret); +const masterAccountId = SDK.util.getAccountIdFromPrivate(masterSecret); +const masterAddress = sdk.key.classes.PlatformAddress.fromAccountId(masterAccountId); const regularSecret = SDK.util.generatePrivateKey(); const regularPublic = SDK.util.getPublicFromPrivate(regularSecret); @@ -30,7 +31,7 @@ test("setRegularKey", async () => { const nonce2 = await sdk.rpc.chain.getNonce(masterAddress); const p2 = sdk.core.createPaymentParcel({ - recipient: sdk.key.classes.PlatformAddress.fromAccountId(masterAddress), + recipient: masterAddress, amount: 10, }); const hash2 = await sdk.rpc.chain.sendSignedParcel(p2.sign({ diff --git a/integration_tests/useRegistrar.spec.ts b/integration_tests/useRegistrar.spec.ts index 3308c4f9..6a4f5971 100644 --- a/integration_tests/useRegistrar.spec.ts +++ b/integration_tests/useRegistrar.spec.ts @@ -3,10 +3,12 @@ import { SDK } from "../"; const SERVER_URL = process.env.CODECHAIN_RPC_HTTP || "http://localhost:8080"; const sdk = new SDK({ server: SERVER_URL }); const masterSecret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; -const masterAddress = SDK.util.getAccountIdFromPrivate(masterSecret); +const masterAccountId = SDK.util.getAccountIdFromPrivate(masterSecret); +const masterAddress = sdk.key.classes.PlatformAddress.fromAccountId(masterAccountId); const otherSecret = "0000000000000000000000000000000000000000000000000000000000000001"; -const otherAddress = SDK.util.getAccountIdFromPrivate(otherSecret); +const otherAccountId = SDK.util.getAccountIdFromPrivate(otherSecret); +const otherAddress = sdk.key.classes.PlatformAddress.fromAccountId(otherAccountId); const regularSecret = SDK.util.generatePrivateKey(); const regularPublic = SDK.util.getPublicFromPrivate(regularSecret); @@ -44,7 +46,7 @@ async function setRegularKey() { async function sendCCCToOther() { const nonce = await sdk.rpc.chain.getNonce(masterAddress); const p = sdk.core.createPaymentParcel({ - recipient: sdk.key.classes.PlatformAddress.fromAccountId(otherAddress), + recipient: otherAddress, amount: 100, }); const hash = await sdk.rpc.chain.sendSignedParcel(p.sign({ @@ -67,7 +69,7 @@ async function mintAssetUsingMaster(p2pkh, aliceAddress, bobAddress) { icon_url: "https://gold.image/", }), amount: 10000, - registrar: sdk.key.classes.PlatformAddress.fromAccountId(masterAddress), + registrar: masterAddress, }); const mintTx = sdk.core.createAssetMintTransaction({ diff --git a/src/rpc/chain.ts b/src/rpc/chain.ts index 87abb6ce..31b7d275 100644 --- a/src/rpc/chain.ts +++ b/src/rpc/chain.ts @@ -1,7 +1,6 @@ import { Rpc } from "."; import { H256 } from "../core/H256"; import { SignedParcel } from "../core/SignedParcel"; -import { H160 } from "../core/H160"; import { U256 } from "../core/U256"; import { AssetScheme } from "../core/AssetScheme"; import { Block } from "../core/Block"; @@ -55,7 +54,7 @@ export class ChainRpc { * @throws When the given passphrase does not match */ async sendParcel(parcel: Parcel, options?: { - account?: PlatformAddress | H160 | string, + account?: PlatformAddress | string, passphrase?: string, nonce?: U256 | string | number, fee?: U256 | string | number, @@ -128,10 +127,10 @@ export class ChainRpc { * @param blockNumber The specific block number to get account's regular key at given address. * @returns The regular key of account at specified block, or null when address was not found. */ - getRegularKey(address: PlatformAddress | H160 | string, blockNumber?: number): Promise { + getRegularKey(address: PlatformAddress | string, blockNumber?: number): Promise { return this.rpc.sendRpcRequest( "chain_getRegularKey", - [`0x${PlatformAddress.ensureAccount(address).value}`, blockNumber || null] + [`${PlatformAddress.ensure(address).value}`, blockNumber || null] ).then(result => result === null ? null : new H512(result)); } @@ -176,10 +175,10 @@ export class ChainRpc { * @param blockNumber The specific block number to get account's balance at given address. * @returns Balance of account at specified block, or null when address was not found. */ - getBalance(address: PlatformAddress | H160 | string, blockNumber?: number): Promise { + getBalance(address: PlatformAddress | string, blockNumber?: number): Promise { return this.rpc.sendRpcRequest( "chain_getBalance", - [`0x${PlatformAddress.ensureAccount(address).value}`, blockNumber] + [`${PlatformAddress.ensure(address).value}`, blockNumber] ).then(result => result ? new U256(result) : null); } @@ -189,10 +188,10 @@ export class ChainRpc { * @param blockNumber The specific block number to get account's nonce at given address. * @returns Nonce of account at specified block, or null when address was not found. */ - getNonce(address: PlatformAddress | H160 | string, blockNumber?: number): Promise { + getNonce(address: PlatformAddress | string, blockNumber?: number): Promise { return this.rpc.sendRpcRequest( "chain_getNonce", - [`0x${PlatformAddress.ensureAccount(address).value}`, blockNumber] + [`${PlatformAddress.ensure(address).value}`, blockNumber] ).then(result => result ? new U256(result) : null); }