All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.crldev.elrondspringbootstarterreactive.interactor.smartcontract.ErdSmartContractInteractorImpl Maven / Gradle / Ivy

Go to download

A SpringBoot Starter solution designed to ensure easy and efficient integration with the Elrond Network using a Reactive API layer.

The newest version!
package software.crldev.elrondspringbootstarterreactive.interactor.smartcontract;

import reactor.core.publisher.Mono;
import software.crldev.elrondspringbootstarterreactive.api.ApiResourceURI;
import software.crldev.elrondspringbootstarterreactive.api.model.*;
import software.crldev.elrondspringbootstarterreactive.client.ErdProxyClient;
import software.crldev.elrondspringbootstarterreactive.domain.smartcontract.ContractFunction;
import software.crldev.elrondspringbootstarterreactive.domain.smartcontract.ContractQuery;
import software.crldev.elrondspringbootstarterreactive.domain.wallet.Wallet;
import software.crldev.elrondspringbootstarterreactive.interactor.WrappedResponses;
import software.crldev.elrondspringbootstarterreactive.interactor.transaction.ErdTransactionInteractor;
import software.crldev.elrondspringbootstarterreactive.interactor.transaction.TransactionRequest;

public class ErdSmartContractInteractorImpl implements ErdSmartContractInteractor {
    private final ErdProxyClient client;
    private final ErdTransactionInteractor tInteractor;

    @Override
    public Mono callFunction(Wallet wallet, ContractFunction function) {
        return tInteractor.sendTransaction(wallet, TransactionRequest.builder().receiverAddress(function.getSmartContractAddress()).data(function.getPayloadData()).value(function.getValue()).gasLimit(function.getGasLimit()).build());
    }

    @Override
    public Mono query(ContractQuery query) {
        return client.post(ApiResourceURI.QUERY_SMART_CONTRACT.getURI(), query.toSendable(), WrappedResponses.ScQueryResponse.class).map(WrappedResponses.ScQueryResponse::getResult);
    }

    @Override
    public Mono queryHex(ContractQuery query) {
        return client.post(ApiResourceURI.QUERY_SMART_CONTRACT_HEX.getURI(), query.toSendable(), ContractQueryResultHex.class);
    }

    @Override
    public Mono queryString(ContractQuery query) {
        return client.post(ApiResourceURI.QUERY_SMART_CONTRACT_STRING.getURI(), query.toSendable(), ContractQueryResultString.class);
    }

    @Override
    public Mono queryInt(ContractQuery query) {
        return client.post(ApiResourceURI.QUERY_SMART_CONTRACT_INT.getURI(), query.toSendable(), ContractQueryResultInt.class);
    }

    public ErdSmartContractInteractorImpl(final ErdProxyClient client, final ErdTransactionInteractor tInteractor) {
        this.client = client;
        this.tInteractor = tInteractor;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy