I am new to DAML, I wanted to query all the active contracts using Java binding, Bot API and keep them into DB (or in-memory) for future query.
As per the docs, LedgerView can keep track of active contracts in-memory. However I am not able to successfully stream the active contracts.
You can find my code here, https://github.com/agrawald/daml-java-bot. The above code have a schedule task which I am not very proud of.
The code for the class where I create DamlLedgerClient
and start a schedule job to trigger the Bot
. Please note
@Slf4j
@Service
@RequiredArgsConstructor
public class DamlContractSvc implements InitializingBean {
@Value("${daml.host}")
private String host;
@Value("${daml.port}")
private int port;
@Value("${daml.appId}")
private String appId;
@Value("${daml.party}")
private String party;
@Value("${daml.packageId}")
private String packageId;
@Autowired(required = true)
private ContractCache contractCache;
private DamlLedgerClient client;
@Scheduled(fixedDelay = 5000)
public void fetch() {
final TransactionFilter transactionFilter = new FiltersByParty(
Collections.singletonMap(party, NoFilter.instance));
Bot.wire(appId, client, transactionFilter, (ledgerView) -> Flowable.empty(),
contractCache);
}
@Override
public void afterPropertiesSet() throws Exception {
client = DamlLedgerClient.forHostWithLedgerIdDiscovery(host, port, Optional.empty());
client.connect();
}
}
I believe I should be running some Command
at (ledgerView) -> Flowable.empty()
.
contractCache
is a class which takesCreatedContract
object and load it in the cache.
I may be doing something entirely wrong. please correct me.