mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-21 14:47:12 +01:00
feat(protobuf): support sint in proto codegen
This commit is contained in:
@@ -2,6 +2,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const UINT_TYPE = 'UintType';
|
||||
const SINT_TYPE = 'SintType';
|
||||
const DeviceModelInternal = 'DeviceModelInternal';
|
||||
|
||||
// type rule fixes, ideally it should not be here
|
||||
@@ -130,7 +131,7 @@ const TYPE_PATCH = {
|
||||
'CardanoSignTxInit.ttl': UINT_TYPE,
|
||||
'CardanoSignTxInit.validity_interval_start': UINT_TYPE,
|
||||
'CardanoSignTxInit.total_collateral': UINT_TYPE,
|
||||
'CardanoToken.mint_amount': 'number | string', // TODO: Sint64 support
|
||||
'CardanoToken.mint_amount': SINT_TYPE,
|
||||
'CardanoNativeScript.invalid_before': UINT_TYPE,
|
||||
'CardanoNativeScript.invalid_hereafter': UINT_TYPE,
|
||||
'EosAsset.symbol': 'string',
|
||||
@@ -313,4 +314,5 @@ module.exports = {
|
||||
DEFINITION_PATCH,
|
||||
SKIP,
|
||||
UINT_TYPE,
|
||||
SINT_TYPE,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const json = require('../messages.json');
|
||||
const { RULE_PATCH, TYPE_PATCH, DEFINITION_PATCH, SKIP, UINT_TYPE } = require('./protobuf-patches');
|
||||
const { RULE_PATCH, TYPE_PATCH, DEFINITION_PATCH, SKIP, UINT_TYPE, SINT_TYPE } = require('./protobuf-patches');
|
||||
|
||||
const INDENT = ' '.repeat(4);
|
||||
|
||||
@@ -160,6 +160,8 @@ const lines = []; // string[]
|
||||
lines.push('// This file is auto generated from data/messages/message.json', '');
|
||||
lines.push('// custom type uint32/64 may be represented as string');
|
||||
lines.push(`export type ${UINT_TYPE} = string | number;`, '');
|
||||
lines.push('// custom type sint32/64');
|
||||
lines.push(`export type ${SINT_TYPE} = string | number;`, '');
|
||||
lines.push(
|
||||
`export enum DeviceModelInternal {
|
||||
T1B1 = 'T1B1',
|
||||
|
||||
@@ -871,7 +871,7 @@ export type CardanoToken = Static<typeof CardanoToken>;
|
||||
export const CardanoToken = Type.Object({
|
||||
asset_name_bytes: Type.String(),
|
||||
amount: Type.Optional(Type.Uint()),
|
||||
mint_amount: Type.Optional(Type.Uint()),
|
||||
mint_amount: Type.Optional(Type.Uint({ allowNegative: true })),
|
||||
});
|
||||
|
||||
export type CardanoTxInlineDatumChunk = Static<typeof CardanoTxInlineDatumChunk>;
|
||||
@@ -2279,7 +2279,7 @@ export const StellarSignTx = Type.Object({
|
||||
timebounds_end: Type.Number(),
|
||||
memo_type: EnumStellarMemoType,
|
||||
memo_text: Type.Optional(Type.String()),
|
||||
memo_id: Type.Optional(Type.String()),
|
||||
memo_id: Type.Optional(Type.Uint()),
|
||||
memo_hash: Type.Optional(Type.Union([Type.Buffer(), Type.String()])),
|
||||
num_operations: Type.Number(),
|
||||
});
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
// custom type uint32/64 may be represented as string
|
||||
export type UintType = string | number;
|
||||
|
||||
// custom type sint32/64
|
||||
export type SintType = string | number;
|
||||
|
||||
export enum DeviceModelInternal {
|
||||
T1B1 = 'T1B1',
|
||||
T2T1 = 'T2T1',
|
||||
@@ -783,7 +786,7 @@ export type CardanoAssetGroup = {
|
||||
export type CardanoToken = {
|
||||
asset_name_bytes: string;
|
||||
amount?: UintType;
|
||||
mint_amount?: UintType;
|
||||
mint_amount?: SintType;
|
||||
};
|
||||
|
||||
// CardanoTxInlineDatumChunk
|
||||
@@ -2078,7 +2081,7 @@ export type StellarSignTx = {
|
||||
timebounds_end: number;
|
||||
memo_type: StellarMemoType;
|
||||
memo_text?: string;
|
||||
memo_id?: string;
|
||||
memo_id?: UintType;
|
||||
memo_hash?: Buffer | string;
|
||||
num_operations: number;
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@ export function generate(code: string) {
|
||||
ArrayBuffer: 'Type.ArrayBuffer()',
|
||||
Buffer: 'Type.Buffer()',
|
||||
UintType: 'Type.Uint()',
|
||||
SintType: 'Type.Uint({ allowNegative: true })',
|
||||
};
|
||||
const customTypePlaceholder = Object.keys(customTypesMapping).map(t => `type ${t} = any;`);
|
||||
// Run generator
|
||||
|
||||
@@ -5,6 +5,12 @@ exports[`codegen should generate code for protobuf messages example 1`] = `
|
||||
import { Type, Static } from '@trezor/schema-utils';
|
||||
|
||||
|
||||
export type Type.Uint() = Static<typeof Type.Uint()>
|
||||
export const Type.Uint() = Type.Union([
|
||||
Type.String(),
|
||||
Type.Number()
|
||||
])
|
||||
|
||||
export enum DeviceModelInternal { T1B1 = 'T1B1', T2T1 = 'T2T1', T2B1 = 'T2B1' }
|
||||
|
||||
export type EnumDeviceModelInternal = Static<typeof EnumDeviceModelInternal>
|
||||
|
||||
Reference in New Issue
Block a user