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

前端 未结 1 1546
旧巷少年郎
旧巷少年郎 2021-01-14 22:46

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 en

相关标签:
1条回答
  • 2021-01-14 23:23
    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))));
    
    0 讨论(0)
提交回复
热议问题