Skip to content

Commit

Permalink
Merge pull request #120 from wavesplatform/update_protobuf_schemas
Browse files Browse the repository at this point in the history
Update protobuf schemas
  • Loading branch information
DrBlast authored Feb 6, 2024
2 parents 85c1da6 + 915f084 commit df16cb3
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 245 deletions.
132 changes: 73 additions & 59 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@waves/waves-transactions",
"version": "4.2.10",
"version": "4.3.10",
"description": "Build and sign(multi-sign) transactions for Waves blockchain.",
"keywords": [
"waves",
Expand Down Expand Up @@ -54,15 +54,15 @@
"rimraf": "^2.6.2",
"terser-webpack-plugin": "^1.2.3",
"ts-jest": "^24.0.2",
"ts-jsdoc": "^3.0.1",
"ts-loader": "^5.3.3",
"ts-jsdoc": "^3.2.2",
"ts-loader": "^5.4.5",
"ts-node": "^7.0.1",
"tslint": "^5.20.1",
"typed-ts-events": "^1.1.1",
"typedoc": "^0.19.2",
"typedoc-clarity-theme": "^1.1.0",
"typedoc-plugin-external-module-name": "^2.1.0",
"typescript": "^3.7.2",
"typescript": "^3.9.10",
"typescript-json-schema": "^0.43.0",
"webpack": "^4.30.0",
"webpack-cli": "^3.1.0"
Expand All @@ -73,10 +73,10 @@
},
"dependencies": {
"@waves/marshall": "^0.15.0-beta.1",
"@waves/node-api-js": "^1.2.10",
"@waves/protobuf-serialization": "1.4.3",
"@waves/node-api-js": "^1.3.10",
"@waves/protobuf-serialization": "1.5.2",
"@waves/ts-lib-crypto": "1.4.3",
"@waves/ts-types": "1.1.0",
"@waves/ts-types": "1.2.0",
"axios": "^0.19.0",
"long": "^4.0.0"
}
Expand Down
21 changes: 13 additions & 8 deletions src/proto-serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ export function protoBytesToSignedTx(bytes: Uint8Array): TTx {

export function protoBytesToTx(bytes: Uint8Array): TTransaction {
const t = wavesProto.waves.Transaction.decode(bytes)
const res = protoTxDataToTx(t)

return res
return protoTxDataToTx(t)
}

export function protoTxDataToTx(t: wavesProto.waves.Transaction): TTransaction {
Expand Down Expand Up @@ -189,7 +187,7 @@ export function protoTxDataToTx(t: wavesProto.waves.Transaction): TTransaction {
if (de.hasOwnProperty('intValue')) return {
key: de.key,
type: 'integer',
value: convertNumber(de.intValue!)
value: convertNumber(de.intValue!),
}
if (de.hasOwnProperty('stringValue')) return {key: de.key, type: 'string', value: de.stringValue}
return {key: de.key, value: null}
Expand All @@ -213,7 +211,7 @@ export function protoTxDataToTx(t: wavesProto.waves.Transaction): TTransaction {
}
res.payment = t.invokeScript!.payments!.map(p => ({
amount: convertNumber(p.amount!),
assetId: p.hasOwnProperty('assetId') ? base58Encode(p.assetId!) : null
assetId: p.hasOwnProperty('assetId') ? base58Encode(p.assetId!) : null,
}))
break
case 'updateAssetInfo':
Expand Down Expand Up @@ -436,6 +434,7 @@ export const signedTxToProto = (t: TTx): wavesProto.waves.ISignedTransaction =>

const orderToProto = (o: any): wavesProto.waves.IOrder => {
let priceMode
let attachment
if (o.version === 4 && 'priceMode' in o) {
if (o.priceMode === 0 || o.priceMode === 'default') {
priceMode = undefined
Expand All @@ -445,6 +444,10 @@ const orderToProto = (o: any): wavesProto.waves.IOrder => {
: priceMode = wavesProto.waves.Order.PriceMode.FIXED_DECIMALS
} else priceMode = undefined

if (o.version === 4 && 'attachment' in o) {
attachment = base64Decode(o.attachment.startsWith('base64:') ? o.attachment.slice(7) : o.attachment)
} else attachment = undefined

const isNullOrWaves = (asset: string | null) => asset == null || asset.toLowerCase() == 'waves'
return ({
chainId: o.chainId,
Expand All @@ -464,6 +467,7 @@ const orderToProto = (o: any): wavesProto.waves.IOrder => {
proofs: o.proofs?.map(base58Decode),
eip712Signature: o.eip712Signature ? base16Decode(o.eip712Signature.slice(2)) : undefined,
priceMode: priceMode,
attachment: attachment,
})
}

Expand All @@ -473,7 +477,7 @@ const orderFromProto = (po: wavesProto.waves.IOrder): SignedIExchangeTransaction
po.priceMode === 1
? priceMode = 'fixedDecimals'
: priceMode = 'assetDecimals'
}
} else priceMode = undefined

return {
version: po.version! as 1 | 2 | 3 | 4,
Expand All @@ -492,9 +496,10 @@ const orderFromProto = (po: wavesProto.waves.IOrder): SignedIExchangeTransaction
expiration: po.expiration!.toNumber(),
matcherFee: convertNumber(po.matcherFee!.amount!),
matcherFeeAssetId: po.matcherFee!.assetId == null ? null : base58Encode(po.matcherFee!.assetId),
attachment: po.attachment?.length ? base64Encode(po.attachment) : undefined,
// @ts-ignore
priceMode: priceMode,
eip712Signature: po.eip712Signature?.length ? `0x${base16Encode(po.eip712Signature)}` : undefined
eip712Signature: po.eip712Signature?.length ? `0x${base16Encode(po.eip712Signature)}` : undefined,
}
}

Expand All @@ -510,7 +515,7 @@ const massTransferItemToProto = (mti: MassTransferItem): wavesProto.waves.MassTr
recipient: recipientToProto(mti.recipient),
amount: mti.amount == 0 ? null : Long.fromValue(mti.amount),
})
export const dataEntryToProto = (de: DataTransactionEntry): wavesProto.waves.DataTransactionData.IDataEntry => ({
export const dataEntryToProto = (de: DataTransactionEntry): wavesProto.waves.IDataEntry => ({
key: de.key,
intValue: de.type === 'integer' ? Long.fromValue(de.value) : undefined,
boolValue: de.type === 'boolean' ? de.value : undefined,
Expand Down
1 change: 1 addition & 0 deletions src/requests/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function order(paramsOrOrder: any, seed?: TSeedTypes): SignedIExchangeTra
// @ts-ignore
ord.chainId = networkByte(paramsOrOrder.chainId, 87)
if (paramsOrOrder.eip712Signature) ord.eip712Signature = paramsOrOrder.eip712Signature
if (paramsOrOrder.attachment) ord.attachment = paramsOrOrder.attachment
}

const bytes = ord.version > 3 ? orderToProtoBytes(ord) : binary.serializeOrder(ord)
Expand Down
4 changes: 2 additions & 2 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TransactionType
} from '@waves/ts-types/src'
import {InvokeScriptCallArgument} from '@waves/ts-types/src/parts'
import {EthereumTransaction} from '@waves/ts-types'
import {EthereumTransaction, ExchangeTransactionOrderType} from '@waves/ts-types'

export interface WithId {
/**
Expand Down Expand Up @@ -190,7 +190,7 @@ export interface IOrderParams<LONG = string | number> {
matcherPublicKey: string
price: LONG
amount: LONG
orderType: 'buy' | 'sell',
orderType: ExchangeTransactionOrderType,
amountAsset: string | null
priceAsset: string | null
senderPublicKey?: string
Expand Down
53 changes: 28 additions & 25 deletions test/proto-serialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { exampleTxs } from './exampleTxs'
import {broadcast, libs, waitForTx, WithId} from '../src'
import { protoBytesToTx, txToProtoBytes } from '../src/proto-serialize'
import { transfer } from '../src/transactions/transfer'
import { issue } from '../src/transactions/issue'
import { reissue } from '../src/transactions/reissue'
import { alias } from '../src/transactions/alias'
import { burn } from '../src/transactions/burn'
import { data } from '../src/transactions/data'
import { lease } from '../src/transactions/lease'
import { cancelLease } from '../src/transactions/cancel-lease'
import { setScript } from '../src/transactions/set-script'
import { setAssetScript } from '../src/transactions/set-asset-script'
import { invokeScript } from '../src/transactions/invoke-script'
import { sponsorship } from '../src/transactions/sponsorship'
import { txs } from './example-proto-tx'
import { massTransfer } from '../src/transactions/mass-transfer'
import { updateAssetInfo } from '../src/transactions/update-asset-info'
import {exampleTxs} from './exampleTxs'
import {
alias,
broadcast,
burn,
cancelLease,
data,
invokeScript,
issue,
lease,
libs,
massTransfer,
reissue,
setAssetScript,
setScript,
sponsorship,
transfer,
updateAssetInfo,
waitForTx
} from '../src'
import {protoBytesToTx, txToProtoBytes} from '../src/proto-serialize'
import {txs} from './example-proto-tx'
import {randomHexString, TIMEOUT} from './integration/config'
import {address} from '@waves/ts-lib-crypto'
import {issueMinimalParams} from './minimalParams'
import {deleteProofsAndId} from "./utils";

import {deleteProofsAndId} from './utils'


const nodeUrl = 'http://localhost:6869/'
Expand All @@ -42,15 +45,15 @@ describe('serialize/deserialize', () => {
it('type: ' + tx.type, () => {
// deleteProofsAndId(tx)
//const parsed = protoBytesToTx(txToProtoBytes(tx))
const txWithoutProofAndId = deleteProofsAndId(tx);
const protoBytes = txToProtoBytes(txWithoutProofAndId);
const parsed = protoBytesToTx(protoBytes);
expect(parsed).toMatchObject(txWithoutProofAndId);
const txWithoutProofAndId = deleteProofsAndId(tx)
const protoBytes = txToProtoBytes(txWithoutProofAndId)
const parsed = protoBytesToTx(protoBytes)
expect(parsed).toMatchObject(txWithoutProofAndId)
})
})

it('correctly serialized transactions', () => {
Object.entries(txs).forEach(([name, { Bytes, Json }]) => {
Object.entries(txs).forEach(([, { Bytes, Json }]) => {
const actualBytes = libs.crypto.base16Encode(txToProtoBytes(Json as any))
const expectedBytes = libs.crypto.base16Encode(libs.crypto.base64Decode(Bytes))
expect(expectedBytes).toBe(actualBytes)
Expand Down
11 changes: 5 additions & 6 deletions test/transactions/burn.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {base64Decode, base64Encode, publicKey} from '@waves/ts-lib-crypto'
import {publicKey} from '@waves/ts-lib-crypto'
import {burn} from '../../src'
import {burnMinimalParams} from '../minimalParams'
import {
checkBinarySerializeDeserialize,
checkProtoSerializeDeserialize,
errorMessageByTemplate,
validateTxSignature
} from '../../test/utils'
import {burnTx} from "./expected/proto/burn.tx"
import {burnBinaryTx} from "./expected/binary/burn.tx"
import {binary} from '@waves/marshall'
} from '../utils'
import {burnTx} from './expected/proto/burn.tx'
import {burnBinaryTx} from './expected/binary/burn.tx'


describe('burn', () => {
Expand Down Expand Up @@ -42,7 +41,7 @@ describe('burn', () => {
it('Should not create with zero amount', () => {
expect(() => burn({
...burnMinimalParams,
amount: 0
amount: 0,
}, stringSeed)).toThrowError('tx "amount", has wrong data: 0. Check tx data.')
})

Expand Down
Loading

0 comments on commit df16cb3

Please sign in to comment.