Skip to content

Instantly share code, notes, and snippets.

@satran004
Last active December 13, 2022 03:24
Show Gist options
  • Save satran004/b33b181c020113113f5976c562b1278b to your computer and use it in GitHub Desktop.
Save satran004/b33b181c020113113f5976c562b1278b to your computer and use it in GitHub Desktop.
Local Tx Monitor Example
import com.bloxbean.cardano.client.exception.CborDeserializationException;
import com.bloxbean.cardano.client.transaction.spec.Transaction;
import com.bloxbean.cardano.client.transaction.util.TransactionUtil;
import com.bloxbean.cardano.yaci.core.common.Constants;
import com.bloxbean.cardano.yaci.helper.LocalClientProvider;
import com.bloxbean.cardano.yaci.helper.LocalTxMonitorClient;
import com.bloxbean.cardano.yaci.helper.model.MempoolStatus;
import java.util.List;
public class LocalTxMonitorSample {
public static void main(String[] args) throws CborDeserializationException {
String nodeSocketFile = "~/cardano-node/preprod/db/node.socket";
long protocolMagic = Constants.PREPROD_PROTOCOL_MAGIC;
LocalClientProvider localClientProvider = new LocalClientProvider(nodeSocketFile, protocolMagic);
localClientProvider.start();
LocalTxMonitorClient localTxMonitorClient = localClientProvider.getTxMonitorClient();
while (true) {
System.out.println("Waiting to acquire next snapshot ...");
List<byte[]> txBytesList = localTxMonitorClient.acquireAndGetMempoolTransactionsAsMono().block();
for(byte[] txBytes: txBytesList) {
String txHash = TransactionUtil.getTxHash(txBytes);
System.out.println("Tx Hash >> " + txHash);
Transaction transaction = Transaction.deserialize(txBytes);
System.out.println("Tx Body >> " + transaction);
}
MempoolStatus mempoolStatus = localTxMonitorClient.getMempoolSizeAndCapacity().block();
System.out.println("Mem Pool >> " + mempoolStatus);
}
}
}
<dependency>
<groupId>com.bloxbean.cardano</groupId>
<artifactId>yaci</artifactId>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>com.bloxbean.cardano</groupId>
<artifactId>cardano-client-lib</artifactId>
<version>0.4.0</version>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment