From 9866b5f1c3865c4ce221a17f9fb6ef57262708dd Mon Sep 17 00:00:00 2001 From: Dennis de Klerk Date: Wed, 22 Aug 2018 12:54:42 +0200 Subject: [PATCH] fix(broken): Transaction constructor signature restored --- package-lock.json | 31 ++++++++++++++++++------------- package.json | 5 +++-- src/avro.ts | 6 +++--- src/builder.ts | 2 +- src/heat-sdk.ts | 28 ++++++++++++++-------------- src/socket.ts | 2 +- src/transaction.ts | 4 ++-- test/builder.test.ts | 24 ++++++++++++------------ 8 files changed, 54 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index baeab76..a88fa4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "heat-sdk", - "version": "0.11.0", + "version": "0.13.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2150,8 +2150,8 @@ "dev": true, "optional": true, "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" + "co": "^4.6.0", + "json-stable-stringify": "^1.0.1" } }, "ansi-regex": { @@ -2270,6 +2270,7 @@ "version": "1.0.5", "bundled": true, "dev": true, + "optional": true, "requires": { "delayed-stream": "~1.0.0" } @@ -2332,7 +2333,8 @@ "delayed-stream": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "delegates": { "version": "1.0.0", @@ -2561,7 +2563,7 @@ "dev": true, "optional": true, "requires": { - "jsbn": "0.1.1" + "jsbn": "~0.1.0" } }, "jsbn": { @@ -2582,7 +2584,7 @@ "dev": true, "optional": true, "requires": { - "jsonify": "0.0.0" + "jsonify": "~0.0.0" } }, "json-stringify-safe": { @@ -2620,12 +2622,14 @@ "mime-db": { "version": "1.27.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "mime-types": { "version": "2.1.15", "bundled": true, "dev": true, + "optional": true, "requires": { "mime-db": "1.27.0" } @@ -2701,7 +2705,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "oauth-sign": { "version": "0.8.2", @@ -2741,8 +2746,8 @@ "dev": true, "optional": true, "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" } }, "path-is-absolute": { @@ -6324,9 +6329,9 @@ "dev": true }, "prettier": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.14.2.tgz", - "integrity": "sha512-McHPg0n1pIke+A/4VcaS2en+pTNjy4xF+Uuq86u/5dyDO59/TtFZtQ708QIRkEZ3qwKz3GVkVa6mpxK/CpB8Rg==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.12.1.tgz", + "integrity": "sha1-wa0g6APndJ+vkFpAnSNn4Gu+cyU=", "dev": true }, "pretty-format": { diff --git a/package.json b/package.json index c92255c..e531b27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "heat-sdk", - "version": "0.12.0", + "version": "0.13.0", "description": "HEAT support libraries for use in Node.js and any (modern) browser", "keywords": [ "heat", @@ -34,6 +34,7 @@ "lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", "prebuild": "rimraf dist", "build": "rollup -c && rimraf compiled && typedoc --sourcefile-url-prefix 'https://github.com/Heat-Ledger-Ltd/heat-sdk/blob/master/src/' --out dist/docs --target es6 --theme minimal src", + "buildfast": "rimraf dist && rollup -c && rimraf compiled", "start": "rollup -c -w", "test": "jest --forceExit", "test:watch": "jest --watch", @@ -98,7 +99,7 @@ "jest": "^21.0.0", "lint-staged": "^4.3.0", "lodash.camelcase": "^4.3.0", - "prettier": "^1.14.2", + "prettier": "1.12.1", "prompt": "^1.0.0", "replace-in-file": "^3.4.2", "rimraf": "^2.6.1", diff --git a/src/avro.ts b/src/avro.ts index 7b6f538..0222692 100644 --- a/src/avro.ts +++ b/src/avro.ts @@ -20,7 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ -import * as Long from "long" +import Long from "long" import { Buffer } from "buffer" import avro from "./avro-types/avro-types" // import a_ from './avro-types' @@ -34,8 +34,8 @@ export const Type = { const longType = avro.types.LongType.__with({ fromBuffer: (buf: any) => { - //return new Long(buf.readInt32LE(0), buf.readInt32LE(4)) - return Long.fromBits(buf.readInt32LE(0), buf.readInt32LE(4)) + return new Long(buf.readInt32LE(0), buf.readInt32LE(4)) + //return Long.fromBits(buf.readInt32LE(0), buf.readInt32LE(4)) }, toBuffer: (n: any) => { //const buf: any = Buffer.alloc(8) diff --git a/src/builder.ts b/src/builder.ts index 51bc976..4be7f58 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -28,7 +28,7 @@ import * as appendix from "./appendix" import * as utils from "./utils" import * as converters from "./converters" import * as crypto from "./crypto" -import * as Long from "long" +import Long from "long" import * as ByteBuffer from "bytebuffer" import { Buffer } from "buffer" diff --git a/src/heat-sdk.ts b/src/heat-sdk.ts index 72dea11..3d5f0a9 100644 --- a/src/heat-sdk.ts +++ b/src/heat-sdk.ts @@ -114,44 +114,44 @@ export class HeatSDK { public payment(recipientOrRecipientPublicKey: string, amount: string) { return new Transaction( this, + recipientOrRecipientPublicKey, new Builder() .isTestnet(this.config.isTestnet) .attachment(attachment.ORDINARY_PAYMENT) - .amountHQT(utils.convertToQNT(amount)), - recipientOrRecipientPublicKey + .amountHQT(utils.convertToQNT(amount)) ) } public arbitraryMessage(recipientOrRecipientPublicKey: string, message: string) { return new Transaction( this, + recipientOrRecipientPublicKey, new Builder() .isTestnet(this.config.isTestnet) .attachment(attachment.ARBITRARY_MESSAGE) - .amountHQT("0"), - recipientOrRecipientPublicKey + .amountHQT("0") ).publicMessage(message) } public privateMessage(recipientPublicKey: string, message: string) { return new Transaction( this, + recipientPublicKey, new Builder() .isTestnet(this.config.isTestnet) .attachment(attachment.ARBITRARY_MESSAGE) - .amountHQT("0"), - recipientPublicKey + .amountHQT("0") ).privateMessage(message) } public privateMessageToSelf(message: string) { return new Transaction( this, + null, // if null and provide private message then to send encrypted message to self new Builder() .isTestnet(this.config.isTestnet) .attachment(attachment.ARBITRARY_MESSAGE) - .amountHQT("0"), - null // if null and provide private message then to send encrypted message to self + .amountHQT("0") ).privateMessageToSelf(message) } @@ -170,7 +170,7 @@ export class HeatSDK { ) .amountHQT("0") .feeHQT(feeHQT ? feeHQT : Fee.ASSET_ISSUANCE_FEE) - return new Transaction(this, builder) + return new Transaction(this, "0", builder) } public assetTransfer( @@ -184,7 +184,7 @@ export class HeatSDK { .attachment(new AssetTransfer().init(assetId, quantity)) .amountHQT("0") .feeHQT(feeHQT ? feeHQT : Fee.ASSET_TRANSFER_FEE) - return new Transaction(this, builder, recipientOrRecipientPublicKey) + return new Transaction(this, recipientOrRecipientPublicKey, builder) } public placeAskOrder( @@ -201,7 +201,7 @@ export class HeatSDK { ) .amountHQT("0") .feeHQT("1000000") - return new Transaction(this, builder) + return new Transaction(this, "0", builder) } public placeBidOrder( @@ -218,7 +218,7 @@ export class HeatSDK { ) .amountHQT("0") .feeHQT("1000000") - return new Transaction(this, builder) + return new Transaction(this, "0", builder) } public cancelAskOrder(orderId: string) { @@ -227,7 +227,7 @@ export class HeatSDK { .attachment(new ColoredCoinsAskOrderCancellation().init(orderId)) .amountHQT("0") .feeHQT("1000000") - return new Transaction(this, builder) + return new Transaction(this, "0", builder) } public cancelBidOrder(orderId: string) { @@ -236,6 +236,6 @@ export class HeatSDK { .attachment(new ColoredCoinsBidOrderCancellation().init(orderId)) .amountHQT("0") .feeHQT("1000000") - return new Transaction(this, builder) + return new Transaction(this, "0", builder) } } diff --git a/src/socket.ts b/src/socket.ts index eeb9bc2..1c7ce96 100644 --- a/src/socket.ts +++ b/src/socket.ts @@ -22,7 +22,7 @@ * */ import WebSocket from "ws" -import * as ByteBuffer from "bytebuffer" +import ByteBuffer from "bytebuffer" import * as utils from "./utils" import { Buffer } from "buffer" diff --git a/src/transaction.ts b/src/transaction.ts index e799343..6c27ba8 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -48,8 +48,8 @@ export class Transaction { constructor( private heatsdk: HeatSDK, - private builder: Builder, - private recipientOrRecipientPublicKey?: string + private recipientOrRecipientPublicKey: string, + private builder: Builder ) {} public sign(secretPhrase: string): Promise { diff --git a/test/builder.test.ts b/test/builder.test.ts index b9292d2..7eab95b 100644 --- a/test/builder.test.ts +++ b/test/builder.test.ts @@ -162,7 +162,7 @@ describe("Transaction builder", () => { .ecBlockId("5555566666") .recipientId("33333") .isTestnet(true) - let txn = new Transaction(heatsdk, builder, "33333") + let txn = new Transaction(heatsdk, "33333", builder) let transaction = builder.build("hello") txn.sign("hello") let unsignedBytes = transaction.getUnsignedBytes() @@ -637,7 +637,7 @@ describe("Transaction builder", () => { .attachment(new AssetIssuance().init("https://abcd", null, "100", 0, true)) .amountHQT("0") .feeHQT("50000000000") - testServerParsing(new Transaction(heatsdk, builder)).then(response => { + testServerParsing(new Transaction(heatsdk, "0", builder)).then(response => { expect(response).toEqual( expect.objectContaining({ fee: "50000000000", @@ -654,7 +654,7 @@ describe("Transaction builder", () => { .attachment(new AssetIssueMore().init(testnet.ASSET_1.ID, "100")) .amountHQT("0") .feeHQT("50000000000") - testServerParsing(new Transaction(heatsdk, builder, "123")).then(response => { + testServerParsing(new Transaction(heatsdk, "123", builder)).then(response => { expect(response.errorDescription.indexOf("NotYetEnabledException")).toBeGreaterThanOrEqual(0) done() }) @@ -665,7 +665,7 @@ describe("Transaction builder", () => { .attachment(new AssetTransfer().init(testnet.ASSET_1.ID, "100")) .amountHQT("0") .feeHQT("50000000000") - testServerParsing(new Transaction(heatsdk, builder, "123")).then(response => { + testServerParsing(new Transaction(heatsdk, "123", builder)).then(response => { expect(response).toEqual( expect.objectContaining({ fee: "50000000000", @@ -690,7 +690,7 @@ describe("Transaction builder", () => { ) .amountHQT("0") .feeHQT("1000000") - testServerParsing(new Transaction(heatsdk, builder)).then(response => { + testServerParsing(new Transaction(heatsdk, "0", builder)).then(response => { expect(response).toEqual( expect.objectContaining({ fee: "1000000", @@ -716,7 +716,7 @@ describe("Transaction builder", () => { ) .amountHQT("0") .feeHQT("1000000") - testServerParsing(new Transaction(heatsdk, builder)).then(response => { + testServerParsing(new Transaction(heatsdk, "0", builder)).then(response => { expect(response).toEqual( expect.objectContaining({ fee: "1000000", @@ -734,7 +734,7 @@ describe("Transaction builder", () => { .amountHQT("0") .feeHQT("1000000") //todo make the real Ask Order and then cancel it - testServerParsing(new Transaction(heatsdk, builder, "123")).then(response => { + testServerParsing(new Transaction(heatsdk, "123", builder)).then(response => { expect(response.errorDescription).toMatch("Invalid ask order cancellation") done() }) @@ -745,7 +745,7 @@ describe("Transaction builder", () => { .attachment(new ColoredCoinsBidOrderCancellation().init("1234567")) .amountHQT("0") .feeHQT("1000000") - testServerParsing(new Transaction(heatsdk, builder, "123")).then(response => { + testServerParsing(new Transaction(heatsdk, "123", builder)).then(response => { expect(response.errorDescription).toMatch("Invalid bid order cancellation") done() }) @@ -762,7 +762,7 @@ describe("Transaction builder", () => { ) .amountHQT("0") .feeHQT("1000000") - testServerParsing(new Transaction(heatsdk, builder, "123")).then(response => { + testServerParsing(new Transaction(heatsdk, "123", builder)).then(response => { expect(response.errorDescription).toMatch("NotYetEnabledException") done() }) @@ -775,7 +775,7 @@ describe("Transaction builder", () => { ) .amountHQT("0") .feeHQT("1000000") - testServerParsing(new Transaction(heatsdk, builder, "123")).then(response => { + testServerParsing(new Transaction(heatsdk, "123", builder)).then(response => { expect(response.errorDescription).toMatch("NotYetEnabledException") done() }) @@ -786,7 +786,7 @@ describe("Transaction builder", () => { .attachment(new ColoredCoinsWhitelistMarket().init("0", testnet.ASSET_1.ID)) .amountHQT("0") .feeHQT("1000000000") - testServerParsing(new Transaction(heatsdk, builder, testnet.ASSET_1.ISSUER.ID)).then( + testServerParsing(new Transaction(heatsdk, testnet.ASSET_1.ISSUER.ID, builder)).then( response => { expect(response.errorDescription).toMatch("Only asset issuer can allow a market") done() @@ -799,7 +799,7 @@ describe("Transaction builder", () => { .attachment(new AccountControlEffectiveBalanceLeasing().init(2)) .amountHQT("0") .feeHQT("1000000") - testServerParsing(new Transaction(heatsdk, builder, "123")).then(response => { + testServerParsing(new Transaction(heatsdk, "123", builder)).then(response => { expect(response.errorDescription).toMatch("Invalid effective balance leasing") done() })