如何将事务动态推送到哈希图的运行方法中?
例如:
在下面的代码中,名称作为事务发布。如何动态获取此值。如果必须通过套接字,启动套接字的最佳位置是哪个?
public void run() {
String myName = platform.getState().getAddressBookCopy().getAddress(selfId).getSelfName();
console.out.println("Hello Swirld from " + myName);
byte[] transaction = myName.getBytes(StandardCharsets.UTF_8);
platform.createTransaction(transaction, null);
String lastReceived = "";
while (true) {
IPOSAppState state = (IPOSAppState) platform.getState();
String received = state.getReceived();
if (!lastReceived.equals(received)) {
lastReceived = received;
console.out.println("Received: " + received); // print all received transactions
}
try {
Thread.sleep(sleepPeriod);
} catch (Exception e) {
}
}
}
任何示例代码都会有帮助。