blockchainethereumhashgraphhedera-hashgraph

How to push transactions dynamically in hashgraph?


How to push transactions dynamically into run method of hash graph?

For instance:

In the below code, the name is published as a transaction. How to get this value dynamically. If it has to be through socket, which is the best place to initiate the socket?

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

Any example code would really help.


Solution

  • This project contains a demonstration of a web application communicating with a Swirld sdk.

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