Is there a way to add more information to a node, except the mandatory ones?

坚强是说给别人听的谎言 提交于 2019-12-06 14:19:46
  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))));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!