如何在哈希图中动态推送交易



如何将事务动态推送到哈希图的运行方法中?

例如:

在下面的代码中,名称作为事务发布。如何动态获取此值。如果必须通过套接字,哪个是启动套接字的最佳位置?

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) {
        }
    }
}    

任何示例代码都会真正有所帮助。

该项目包含一个与 Swirld SDK 通信的 Web 应用程序的演示。

https://github.com/craigdrabiktxmq/exo-demo

新的开源Hedera Hashgraph SDK有更多的选择。Hedera Hashgraph已经实现了协议缓冲区API,用于构建合约,加密货币,通用实用程序,文件系统,服务等。您可以在下面找到 API 的详细信息。

https://github.com/hashgraph/hedera-protobuf

在此存储库本身提供的以下示例中,此 API 有一个用于事务查询的特定实现。

https://github.com/hashgraph/hedera-protobuf/blob/master/Transaction-Query-Examples.md

希望这对您的要求有意义。

最新更新