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

Expose fully-typed config getter to wax base interface

parent 34dd51b2
No related branches found
No related tags found
1 merge request!233Add account authority update complex operation
......@@ -76,6 +76,7 @@ wax_wasm_proto_tsc_generation:
- "${CI_PROJECT_DIR}/ts/wasm/lib/proto" # For documentation generator
- "${CI_PROJECT_DIR}/ts/wasm/lib/build_wasm" # For documentation generator
- "${DIST_DIR}/lib/build_wasm/wax.common.js" # For base WASM tests
- "${DIST_DIR}/lib/build_wasm/types.ts" # For base WASM tests
- "${DIST_DIR}/lib/proto" # For protobuf pattern tests
- "${DIST_DIR}/lib" # For Node.js tests
- "${DIST_DIR}/bundle/index-full.js" # For web tests
......
......@@ -43,6 +43,8 @@ else
-S "${EXECUTION_PATH}/ts/wasm/src" -B "${BUILD_DIR}" 2>&1 | tee -i "${BUILD_DIR}/cmake.log"
ninja -v -j8 2>&1 | tee -i "${BUILD_DIR}/build.log"
cmake --install "${BUILD_DIR}" --component wax_config_ts --prefix "${EXECUTION_PATH}/ts/wasm/lib/build_wasm"
cmake --install "${BUILD_DIR}" --component wax_wasm_common_runtime --prefix "${EXECUTION_PATH}/ts/wasm/lib/build_wasm"
cmake --install "${BUILD_DIR}" --component wax_wasm_common_dts --prefix "${EXECUTION_PATH}/ts/wasm/lib/build_wasm"
......
......@@ -16,6 +16,7 @@ import { WaxFormatter } from "./formatters/waxify.js";
import { isNaiAsset } from "./util/asset_util.js";
import { plainToInstance } from "class-transformer";
import { validateSync } from "class-validator";
import type { IChainConfig } from "../build_wasm/config";
const PERCENT_VALUE_DOUBLE_PRECISION = 100;
export const ONE_HUNDRED_PERCENT = 100 * PERCENT_VALUE_DOUBLE_PRECISION;
......@@ -332,7 +333,7 @@ export class WaxBaseApi implements IWaxBaseInterface {
}
public get addressPrefix(): string {
return safeWasmCall(() => this.proto.cpp_get_address_prefix() as string);
return this.config.HIVE_ADDRESS_PREFIX;
}
public getVersion(): string {
......@@ -355,6 +356,26 @@ export class WaxBaseApi implements IWaxBaseInterface {
}));
}
private cachedConfig: IChainConfig | undefined;
public get config(): IChainConfig {
if (this.cachedConfig === undefined) {
// XXX: This should be an overloaded call with default parameters
const config = safeWasmCall(() => this.protocol.cpp_get_hive_protocol_config("hive.fund", "beeab0de00000000000000000000000000000000000000000000000000000000"));
const configToSave = {} as IChainConfig;
const configKeys = config.keys();
for(let i = 0; i < configKeys.size(); ++i) {
const key = configKeys.get(i) as string;
configToSave[key] = config.get(key) as string;
}
this.cachedConfig = configToSave;
}
return this.cachedConfig;
}
public decrypt(wallet: IBeekeeperUnlockedWallet, encrypted: string): string {
const data = safeWasmCall(() => this.proto.cpp_crypto_memo_from_string(encrypted));
......
......@@ -13,6 +13,7 @@ import type Long from "long";
import type { OperationBase } from "./detailed/operation_base";
import type { BlogPostOperation, AccountAuthorityUpdateOperation, ReplyOperation, DefineRecurrentTransferOperation, RecurrentTransferRemovalOperation, UpdateProposalOperation, WitnessSetPropertiesOperation } from "./detailed/complex_operations";
import type { ResourceCreditsOperation, CommunityOperation, FollowOperation, TAccountName } from './detailed/hive_apps_operations';
import type { IChainConfig } from "./build_wasm/config";
export type TNaiAssetConvertible = number | string | BigInt | Long;
......@@ -567,6 +568,11 @@ export interface IWaxBaseInterface {
*/
getVersion(): string;
/**
* Holds the protocol configuration for the current chain
*/
get config(): IChainConfig;
/**
* Retrieves asset amount and symbol from the api data
*
......
......@@ -53,6 +53,17 @@ set( INCLUDES "${WAX_ROOT_PATH}"
"${HIVE_ROOT_PATH}/libraries/chain/include"
)
include("${CMAKE_CURRENT_SOURCE_DIR}/get_config.d/generate_get_config.cmake")
generate_get_config(
"${CMAKE_CURRENT_SOURCE_DIR}/../../../hive/libraries/protocol/include/hive/protocol/config.hpp" # path to config.hpp
"${CMAKE_CURRENT_SOURCE_DIR}/get_config.d/config.ts.in" # path to get_config template file
"${CMAKE_CURRENT_BINARY_DIR}/config.ts" # output path
)
INSTALL( FILES "${CMAKE_CURRENT_BINARY_DIR}/config.ts"
COMPONENT "wax_config_ts"
DESTINATION .
)
function( DEFINE_WAX_TARGET_FOR env )
set( exec_wasm_name "wax_wasm_${env}" )
set( exec_ts_gen "wax_ts_gen_${env}" )
......
export interface IChainConfig {
"HIVE_CHAIN_ID": string;
"HIVE_TREASURY_ACCOUNT": string;
"VESTS_SYMBOL": string;
"HIVE_SYMBOL": string;
"HBD_SYMBOL": string;
"IS_TEST_NET": string;
"HIVE_ENABLE_SMT": string;
@CONFIG_HPP@
}
macro(generate_get_config path_to_config_hpp get_config_cpp_in get_config_cpp_out)
file(COPY ${path_to_config_hpp} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set(path_to_new_config_hpp "${CMAKE_CURRENT_BINARY_DIR}/config.hpp")
# removing includes and pragmas
file(STRINGS ${path_to_new_config_hpp} file_content )
list(FILTER file_content EXCLUDE REGEX "#(include|pragma)" )
set(prepared_get_content)
foreach(x ${file_content})
list( APPEND prepared_get_content "${x}\n" )
endforeach()
set(_OUT_FILE "${path_to_new_config_hpp}.pregen.preprocessed.hpp" )
set(OUT_FILE "${path_to_new_config_hpp}.preprocessed" )
# rewriting gile
file(WRITE ${_OUT_FILE} ${prepared_get_content} )
# setup compiler flags for dry run
set(local_compiler_flags "-E")
IF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
list(APPEND local_compiler_flags "-fdirectives-only" "${_OUT_FILE}" "-o" "${OUT_FILE}")
ELSE()
list(APPEND local_compiler_flags "-dD" "${_OUT_FILE}" "-o" "${OUT_FILE}")
ENDIF()
if( BUILD_HIVE_TESTNET )
list(APPEND local_compiler_flags "-DIS_TEST_NET")
endif()
if( ENABLE_SMT_SUPPORT )
list(APPEND local_compiler_flags "-DHIVE_ENABLE_SMT")
endif()
# using of compiler dry run to preprocess config.hpp
message("running c++ compiler wit flags: ${local_compiler_flags}")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${local_compiler_flags})
# trim additional output from comiler till the comment from header file
file(STRINGS ${OUT_FILE} config_hpp_content )
set(preambula_on 1)
set(list_of_new_lines)
foreach(line in ${config_hpp_content})
if( ${preambula_on} EQUAL 1 )
string(FIND "${line}" "__HIVE_START_PROTOCOL_DEFINITIONS__" preambula_found )
if( ${preambula_found} GREATER_EQUAL 0 )
set(preambula_on 0)
endif()
continue()
endif()
# parse defines
if(${line} MATCHES "^([ ]*#define)")
string(REGEX REPLACE "#define ([A-Z0-9_]+) .*" "\\1" UNSAFE_VALUE "${line}")
string(STRIP ${UNSAFE_VALUE} VALUE)
if( NOT ${VALUE} STREQUAL "HIVE_CHAIN_ID" )
list( APPEND list_of_new_lines " \"${VALUE}\": string\;\n" )
endif()
endif()
endforeach()
# convert list to single varriable
set(CONFIG_HPP)
foreach(x ${list_of_new_lines})
set(CONFIG_HPP "${CONFIG_HPP}${x}")
endforeach()
configure_file(${get_config_cpp_in} ${get_config_cpp_out} )
message("get_config.cpp has been generated in `${get_config_cpp_out}`")
set(GET_CONFIG_CPP ${get_config_cpp_out})
endmacro()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment