I want to add more node information to a network node. Is it possible to share more data besides what's in the node configuration file? Maybe some custom fields, like an encoded logo image or stuff like that.
Thanks
- Yes you can.
- Inside your module under
src
folder add a file calledconfig.conf
. - Add your values inside of it in the following format:
key1="string_value"
key2=number_value
- Inside
build.gradle
go to the part where you define your nodes, let's say your module name is "my_module"; do this:
cordapp (project(':my_module')) {
config project.file("src/config.conf")
}
- Now when you run
deployNodes
, gradle will generate a file calledmy_module.conf
underbuild\nodes\my_node\cordapps\config
. - To access those values inside your flow:
getServiceHub().getAppContext().getConfig().getString("key1");
- As for testing flows; to mimic the custom config file you need to do the following:
Map<String, String> customConfig = new HashMap<>();
customConfig.put("key1", "string_value");
customConfig.put("key2", "int_value");
// Setup network.
network = new MockNetwork(new MockNetworkParameters().withCordappsForAllNodes(ImmutableList.of(
TestCordapp.findCordapp("my_package").withConfig(customConfig))));
来源:https://stackoverflow.com/questions/58609748/is-there-a-way-to-add-more-information-to-a-node-except-the-mandatory-ones