Skip to content

Commit

Permalink
fix(broken): Transaction constructor signature restored
Browse files Browse the repository at this point in the history
  • Loading branch information
dmdeklerk committed Aug 22, 2018
1 parent 1aa3808 commit 9866b5f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 48 deletions.
31 changes: 18 additions & 13 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/avro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
28 changes: 14 additions & 14 deletions src/heat-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -201,7 +201,7 @@ export class HeatSDK {
)
.amountHQT("0")
.feeHQT("1000000")
return new Transaction(this, builder)
return new Transaction(this, "0", builder)
}

public placeBidOrder(
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction> {
Expand Down
24 changes: 12 additions & 12 deletions test/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
Expand All @@ -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()
})
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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()
})
Expand All @@ -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()
})
Expand All @@ -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()
})
Expand All @@ -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()
})
Expand All @@ -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()
Expand All @@ -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()
})
Expand Down

0 comments on commit 9866b5f

Please sign in to comment.