Skip to content

Commit

Permalink
perf: remove extra number encs/decs
Browse files Browse the repository at this point in the history
Pull in updates from original ilp-packet repo.
  • Loading branch information
sentientwaffle authored and DonChangfoot committed Sep 6, 2019
1 parent 93e78a5 commit 1adc9c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion packages/ilp-packet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
},
"dependencies": {
"extensible-error": "^1.0.2",
"long": "^4.0.0",
"oer-utils": "^5.0.1"
}
}
9 changes: 2 additions & 7 deletions packages/ilp-packet/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Writer } from 'oer-utils'
import Long = require('long')
import BaseError = require('extensible-error')

export const codes = {
Expand Down Expand Up @@ -103,12 +102,8 @@ export class AmountTooLargeError extends BaseError {
this.ilpErrorCode = codes.F08_AMOUNT_TOO_LARGE

const writer = new Writer(8 + 8)
const receivedAmountLong = Long.fromString(opts.receivedAmount, true)
const maximumAmountLong = Long.fromString(opts.maximumAmount, true)
writer.writeUInt32(receivedAmountLong.getHighBitsUnsigned())
writer.writeUInt32(receivedAmountLong.getLowBitsUnsigned())
writer.writeUInt32(maximumAmountLong.getHighBitsUnsigned())
writer.writeUInt32(maximumAmountLong.getLowBitsUnsigned())
writer.writeUInt64(opts.receivedAmount)
writer.writeUInt64(opts.maximumAmount)

this.ilpErrorData = writer.getBuffer()
}
Expand Down
17 changes: 8 additions & 9 deletions packages/ilp-packet/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Predictor, Reader, Writer } from 'oer-utils'
import * as errors from './errors'
import {
dateToInterledgerTime,
interledgerTimeToDate,
INTERLEDGER_TIME_LENGTH
} from './utils/date'
import * as assert from 'assert'
import { dateToInterledgerTime, interledgerTimeToDate, INTERLEDGER_TIME_LENGTH } from './utils/date'

import Long = require('long')
import * as errors from './errors'
export const Errors = errors

export enum Type {
Expand Down Expand Up @@ -56,7 +59,6 @@ export const serializeIlpPrepare = (json: IlpPrepare) => {
assert(typeof (json as Partial<IlpPrepare>).destination === 'string', 'destination is required')
assert(!json.data || Buffer.isBuffer(json.data), 'data must be a buffer')

const amount = Long.fromString(json.amount, true)
const expiresAt = Buffer.from(dateToInterledgerTime(json.expiresAt), 'ascii')
const destination = Buffer.from(json.destination, 'ascii')

Expand All @@ -72,8 +74,7 @@ export const serializeIlpPrepare = (json: IlpPrepare) => {
envelope.writeUInt8(Type.TYPE_ILP_PREPARE)

const content = envelope.createVarOctetString(contentSize)
content.writeUInt32(amount.getHighBitsUnsigned())
content.writeUInt32(amount.getLowBitsUnsigned())
content.writeUInt64(json.amount)
content.write(expiresAt)
content.write(json.executionCondition)
content.writeVarOctetString(destination)
Expand All @@ -90,9 +91,7 @@ export const deserializeIlpPrepare = (binary: Buffer): IlpPrepare => {
}

const reader = Reader.from(contents)
const highBits = reader.readUInt32Number()
const lowBits = reader.readUInt32Number()
const amount = Long.fromBits(+lowBits, +highBits, true).toString()
const amount = reader.readUInt64()
const expiresAt = interledgerTimeToDate(reader.read(INTERLEDGER_TIME_LENGTH).toString('ascii'))
const executionCondition = reader.read(32)
const destination = reader.readVarOctetString().toString('ascii')
Expand Down

0 comments on commit 1adc9c4

Please sign in to comment.