Skip to content
Snippets Groups Projects
Verified Commit c12d7151 authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll:
Browse files

Add formatter for witness set properties operation properties

parent 6bb4174c
No related branches found
No related tags found
2 merge requests!163Release Candidate changes done in develop branch targeted to master,!157Add formatter for witness set properties operation properties
Pipeline #96618 passed
......@@ -13,6 +13,51 @@ export const numToHighLow = (value: number | string | Long): [ number, number ]
return [ long.low, long.high ];
};
export const serializedWitnessSetProperties = {
type: 'witness_set_properties_operation',
value: {
owner: 'gtg',
props: [
[
"account_creation_fee",
"88130000000000002320bcbe",
],
[
"account_subsidy_budget",
"e8030000",
],
[
"account_subsidy_decay",
"e8030000",
],
[
"hbd_exchange_rate",
"e8030000000000000320bcbee8030000000000002320bcbe",
],
[
"hbd_interest_rate",
"e803",
],
[
"key",
"3553544d355271564241564e703575664d4365745174764c474c4a6f37756e58396e7943424d4d7254585257513969315a7a7a697a68",
],
[
"maximum_block_size",
"e8030000",
],
[
"new_signing_key",
"3553544d365471534a61533161526a367036795a456f35786963583762764c6872666456716935546f4e724b78485533465242456457",
],
[
"url",
"0f68747470733a2f2f686976652e696f",
]
]
}
};
export const witness_properties: witness_set_properties_data = {
key: 'STM5RqVBAVNp5ufMCetQtvLGLJo7unX9nyCBMMrTXRWQ9i1Zzzizh',
new_signing_key: 'STM6TqSJaS1aRj6p6yZEo5xicX7bvLhrfdVqi5ToNrKxHU3FRBEdW',
......
......@@ -6,7 +6,7 @@ import fs from "fs";
import { test } from '../assets/jest-helper';
import { initminerAccountApi, naiAsset, serialization_sensitive_transaction, serialization_sensitive_transaction_proto, transfer_operation, vote_operation } from "../assets/data.protocol";
import { initminerAccountApi, naiAsset, serialization_sensitive_transaction, serialization_sensitive_transaction_proto, transfer_operation, vote_operation, serializedWitnessSetProperties } from "../assets/data.protocol";
import { ECommunityOperationActions, EFollowActions, IFormatFunctionArguments, ResourceCreditsOperation, WaxFormattable, operation } from '../../dist/lib';
let browser!: ChromiumBrowser;
......@@ -212,6 +212,16 @@ test.describe('Wax object interface formatters tests', () => {
]);
});
test('Should be able to format witness set properties operation using default formatters from hive chain interface', async({ waxTest }) => {
const retVal = await waxTest(({ chain }, serializedWitnessSetProperties) => {
const data = chain.formatter.format(serializedWitnessSetProperties);
return `${data.value.owner} set new signing key to ${data.value.props.new_signing_key}`;
}, serializedWitnessSetProperties);
expect(retVal).toBe("gtg set new signing key to STM6TqSJaS1aRj6p6yZEo5xicX7bvLhrfdVqi5ToNrKxHU3FRBEdW");
});
test('Should be able to format asset using default formatters from hive chain interface', async({ waxTest }) => {
const retVal = await waxTest(({ chain }, naiAsset) => {
return chain.waxify`Amount: ${naiAsset}`;
......
......@@ -7,7 +7,7 @@ import { WaxError } from '../errors.js';
import { TransactionBuilder } from "./transaction_builder.js";
import Long from "long";
import { WaxFormatter } from "./formatters/waxify";
import { WaxFormatter } from "./formatters/waxify.js";
const PERCENT_VALUE_DOUBLE_PRECISION = 100;
export const ONE_HUNDRED_PERCENT = 100 * PERCENT_VALUE_DOUBLE_PRECISION;
......@@ -28,6 +28,14 @@ export class WaxBaseApi implements IWaxBaseInterface {
return this.formatter.waxify.bind(this.formatter);
}
public deserializeWitnessProps(serializedWitnessProps: Array<[string, string]>): witness_set_properties_data {
const map = new this.wax.MapStringString();
for (const [key, serializedValue] of serializedWitnessProps)
map.set(key, serializedValue);
return this.proto.cpp_deserialize_witness_set_properties(map);
}
public serializeWitnessProps(witnessProps: witness_set_properties_data): Record<string, string> {
const propsSerialized = this.proto.cpp_serialize_witness_set_properties(witnessProps);
const propsKeys = propsSerialized.keys();
......
import type { ApiTransaction, NaiAsset } from "../api";
import type { DeepReadonly, IFormatFunctionArguments, IWaxCustomFormatter, IWaxFormatterOptions } from "./types";
import type { IWaxBaseInterface } from "../../interfaces";
import type { custom_json, transaction } from "../../protocol";
import type { custom_json, transaction, witness_set_properties } from "../../protocol";
import { WaxFormattable } from "../decorators/formatters";
import { CommunityOperation, ECommunityOperationActions, EFollowActions, EFollowOperationActions, FollowOperation, ReblogOperation, ResourceCreditsOperation } from "../custom_jsons";
import { WaxBaseApi } from "../base_api";
export class DefaultFormatters implements IWaxCustomFormatter {
public constructor(
......@@ -113,4 +114,29 @@ export class DefaultFormatters implements IWaxCustomFormatter {
return new FollowOperation(what as EFollowActions, follower, followingParsed);
} catch {}
}
@WaxFormattable({ matchProperty: "props" })
public witnessSetPropertiesPropsFormatter({ source }: IFormatFunctionArguments<witness_set_properties>): witness_set_properties | void {
try {
// Make sure we are deserializing the proper operation
if (!("owner" in source))
return;
const props: Array<[string, string]> = [];
if (Array.isArray(source.props)) // API type
props.push(...source.props);
else // Protobuf type
for (const key in source.props)
props.push([key, source.props[key]]);
const deserialized = (this.wax as WaxBaseApi).deserializeWitnessProps(props);
return { // Rewrite the operation with the deserialized props
extensions: [...(source.extensions || [])],
owner: source.owner,
props: deserialized as Record<string, any>
};
} catch {}
}
}
......@@ -12,7 +12,9 @@ export type {
protocol_foundation,
result,
price,
witness_set_properties_data
witness_set_properties_data,
MapStringString,
VectorString
} from './build_wasm/wax.common.js';
declare function waxmodule(): Promise<MainModule>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment