Skip to content

Commit

Permalink
add support for personal->external add movement
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Dec 14, 2020
1 parent fdd43e9 commit 069a253
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
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 069a253

Please sign in to comment.