0 votes
1 view
in Blockchain by (12.8k points)

How to push transactions dynamically into the run method of the 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 a 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.

1 Answer

0 votes
by (29.8k points)

Hi, you can refernce the project link i am mentioning below, it contains a demonstration of a web application communicating with a Swirld sdk.

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...