Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const orderFromProto = (po: wavesProto.waves.IOrder): TOrder => ({
version: po.version! as 1 | 2 | 3,
senderPublicKey: base58Encode(po.senderPublicKey!),
matcherPublicKey: base58Encode(po.matcherPublicKey!),
assetPair: {
amountAsset: po!.assetPair!.amountAssetId == null ? null : base58Encode(po!.assetPair!.amountAssetId),
priceAsset: po!.assetPair!.priceAssetId == null ? null : base58Encode(po!.assetPair!.priceAssetId)
},
// @ts-ignore
chainId: po.chainId,
orderType: po.orderSide === wavesProto.waves.Order.Side.BUY ? 'buy' : 'sell',
amount: po.amount!.toString(),
price: po.price!.toString(),
timestamp: po.timestamp!.toNumber(),
expiration: po.expiration!.toNumber(),
matcherFee: po.matcherFee!.amount!.toNumber(),
matcherFeeAssetId: po.matcherFee!.assetId == null ? null : base58Encode(po.matcherFee!.assetId),
})
const orderToProto = (o: IOrder & { chainId: number }): wavesProto.waves.IOrder => ({
chainId: o.chainId,
senderPublicKey: base58Decode(o.senderPublicKey),
matcherPublicKey: base58Decode(o.matcherPublicKey),
assetPair: {
amountAssetId: o.assetPair.amountAsset == null ? null : base58Decode(o.assetPair.amountAsset),
priceAssetId: o.assetPair.priceAsset == null ? null : base58Decode(o.assetPair.priceAsset)
},
orderSide: o.orderType === "buy" ? undefined : wavesProto.waves.Order.Side.SELL,
amount: Long.fromValue(o.amount),
price: Long.fromValue(o.price),
timestamp: Long.fromValue(o.timestamp),
expiration: Long.fromValue(o.expiration),
matcherFee: amountToProto(o.matcherFee, null),
version: o.version,
proofs: o.proofs.map(base58Decode),
})