Skip to content

Commit

Permalink
Merge pull request #28 from nash-io/ts/add-movement-external
Browse files Browse the repository at this point in the history
add support for personal->external add movement
  • Loading branch information
localhuman authored Dec 16, 2020
2 parents fdd43e9 + bef69e8 commit 6abf674
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [3.3.21](https://github.com/nash-io/nash-protocol/compare/v3.3.11...v3.3.21) (2020-12-16)

### [3.3.11](https://github.com/nash-io/nash-protocol/compare/v3.4.7...v3.3.11) (2020-08-11)

### [3.3.7](https://github.com/nash-io/nash-protocol/compare/v3.3.5...v3.3.7) (2020-07-16)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neon-exchange/nash-protocol",
"version": "3.3.12",
"version": "3.3.21",
"description": "TypeScript implementation of Nash crypto routines",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/payload/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export interface SignedState extends SyncState {

export const MovementTypeDeposit = 'DEPOSIT'
export const MovementTypeWithdrawal = 'WITHDRAWAL'
// This is used for personal -> external
export const MovementTypeTransfer = 'TRANSFER'

export const BuyOrSellBuy = 'BUY'
export const BuyOrSellSell = 'SELL'

Expand Down
18 changes: 13 additions & 5 deletions src/payload/signingPayloadID.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MovementTypeWithdrawal, MovementTypeDeposit } from './payload'
import { MovementTypeWithdrawal, MovementTypeDeposit, MovementTypeTransfer } from './payload'

/**
* IDs mapping Nash Matching Engine operations with handling strategies.
Expand Down Expand Up @@ -101,15 +101,20 @@ export function isStateSigning(kind: SigningPayloadID): boolean {
return kind === SigningPayloadID.signStatesPayload
}

export function needBlockchainSignature(kind: SigningPayloadID): boolean {
return (
export function needBlockchainSignature(kind: SigningPayloadID, payload): boolean {
if (
[
SigningPayloadID.placeLimitOrderPayload,
SigningPayloadID.placeMarketOrderPayload,
SigningPayloadID.placeStopLimitOrderPayload,
SigningPayloadID.placeStopMarketOrderPayload,
SigningPayloadID.addMovementPayload
SigningPayloadID.placeStopMarketOrderPayload
].indexOf(kind) > -1
) {
return true
}

return (
kind === SigningPayloadID.addMovementPayload && [MovementTypeDeposit, MovementTypeWithdrawal].includes(payload.type)
)
}

Expand Down Expand Up @@ -139,6 +144,9 @@ export function kindToOrderPrefix(kind: SigningPayloadID, payload?: any): string
if (kind === SigningPayloadID.addMovementPayload && payload.type === MovementTypeWithdrawal) {
return '03'
}
if (kind === SigningPayloadID.addMovementPayload && payload.type === MovementTypeTransfer) {
return ''
}

throw new Error(`invalid kind given ${kindToName(kind)}`)
}
4 changes: 2 additions & 2 deletions src/signPayload/signPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function signPayload(
pers: null
})

if (needBlockchainSignature(kind)) {
if (needBlockchainSignature(kind, payload)) {
if (config === undefined) {
throw new Error('blockchain signatures needs a Config object')
}
Expand Down Expand Up @@ -208,7 +208,7 @@ export async function preSignPayload(
pers: null
})

if (needBlockchainSignature(kind)) {
if (needBlockchainSignature(kind, payload)) {
if (config == null) {
throw new Error('blockchain signatures needs a Config object')
}
Expand Down

0 comments on commit 6abf674

Please sign in to comment.