-->

Is there a way to add more information to a node,

2020-03-27 11:05发布

问题:

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

回答1:

  1. Yes you can.
  2. Inside your module under src folder add a file called config.conf.
  3. Add your values inside of it in the following format:
key1="string_value"
key2=number_value
  1. 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")
}
  1. Now when you run deployNodes, gradle will generate a file called my_module.conf under build\nodes\my_node\cordapps\config.
  2. To access those values inside your flow:
getServiceHub().getAppContext().getConfig().getString("key1");
  1. 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))));


标签: corda