Last active
December 13, 2022 03:24
-
-
Save satran004/b33b181c020113113f5976c562b1278b to your computer and use it in GitHub Desktop.
Local Tx Monitor Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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