Search in sources :

Example 1 with MosaicTransfer

use of com.github.rosklyar.client.transaction.domain.mosaic.MosaicTransfer in project nem-library by rosklyar.

the class TransactionClientTest method makeMosaicTransfer.

@Test
void makeMosaicTransfer() {
    MosaicTransfer mosaicTransfer = MosaicTransfer.builder().mosaicId(new MosaicId("library", "testcoin")).quantity(3000).build();
    NemAnnounceResult nemAnnounceResult = transactionClient.transferMosaics("fcf0dadc958510dca65651df81aa22c82b2bfe5b29bf8dfb92816bc5f1f11a54", "TDIOE7BZR4J3DXNJ4SL6WOE4HM3QUI3PVUWW3YI3", newArrayList(mosaicTransfer), 2, "test mosaic", 3600);
    assertEquals(1, nemAnnounceResult.code);
}
Also used : MosaicTransfer(com.github.rosklyar.client.transaction.domain.mosaic.MosaicTransfer) MosaicId(com.github.rosklyar.client.transaction.domain.mosaic.MosaicId) NemAnnounceResult(com.github.rosklyar.client.transaction.domain.NemAnnounceResult) Test(org.junit.jupiter.api.Test)

Example 2 with MosaicTransfer

use of com.github.rosklyar.client.transaction.domain.mosaic.MosaicTransfer in project nem-library by rosklyar.

the class TransactionClientTest method multisigMosaicTransfer.

@Test
void multisigMosaicTransfer() {
    MosaicTransfer mosaicTransfer = MosaicTransfer.builder().mosaicId(new MosaicId("library", "testcoin")).quantity(3000).build();
    NemAnnounceResult nemAnnounceResult = transactionClient.multisigTransferMosaics("2ee2a08ad2ebc1371330c9977d15e52f482aa514554e085bec5ed076e8b11581", "TCHCCSUCSBE2OSYXLISPYGOVLOVZYCYYI5V73K4Y", newArrayList(mosaicTransfer), 2, "test multisig", "d9728f3002d6292d54aa2e5c75f1e72bb7f7b800645c46e91171935285e77747", 3600);
    assertEquals(1, nemAnnounceResult.code);
}
Also used : MosaicTransfer(com.github.rosklyar.client.transaction.domain.mosaic.MosaicTransfer) MosaicId(com.github.rosklyar.client.transaction.domain.mosaic.MosaicId) NemAnnounceResult(com.github.rosklyar.client.transaction.domain.NemAnnounceResult) Test(org.junit.jupiter.api.Test)

Example 3 with MosaicTransfer

use of com.github.rosklyar.client.transaction.domain.mosaic.MosaicTransfer in project nem-library by rosklyar.

the class DefaultFeeCalculator method mosaicFee.

private long mosaicFee(MosaicTransfer mosaicTransfer, int times) {
    String namespaceId = mosaicTransfer.mosaicId.namespaceId;
    String mosaicName = mosaicTransfer.mosaicId.name;
    MosaicsMetaDataResponse mosaicsMetaDataResponse = mosaicClient.mosaics(namespaceId, null, 100);
    MosaicMetaData mosaicMetaData = mosaicsMetaDataResponse.data.stream().filter(mmd -> mmd.mosaic.id.name.equals(mosaicName)).findFirst().orElseThrow(() -> new RuntimeException(String.format("No mosaic definition with name=%s found in namespace=%s", mosaicName, namespaceId)));
    int divisibility = mosaicMetaData.mosaic.properties.stream().filter(pr -> pr.name.equals("divisibility")).findFirst().map(pr -> Integer.valueOf(pr.value)).orElseThrow(RuntimeException::new);
    OwnedMosaicsResponse ownedMosaicsResponse = accountClient.ownedMosaics(accountClient.getFromPublicKey(mosaicMetaData.mosaic.creator).account.address);
    long mosaicQuantity = ownedMosaicsResponse.data.stream().filter(ownedMosaic -> ownedMosaic.mosaicId.name.equals(mosaicName)).findFirst().map(ownedMosaic -> ownedMosaic.quantity).orElseThrow(RuntimeException::new);
    if (isSmallBusinessMosaic(divisibility, mosaicQuantity)) {
        return 1L;
    }
    long supplyRelatedAdjustment = roundToLong(0.8 * log(valueOf(maxMosaicQuantity).divide(valueOf(mosaicQuantity)).doubleValue()), DOWN);
    long xemEquivalent = roundToLong(valueOf(8999999999L * mosaicTransfer.quantity * times).divide(valueOf(mosaicQuantity)).doubleValue(), DOWN);
    long microXemEquivalent = xemEquivalent * TEN.pow(nemDivisibility).longValue();
    long xemFee = calculateXemTransferFee(microXemEquivalent);
    return max(1L, xemFee - supplyRelatedAdjustment);
}
Also used : AccountClient(com.github.rosklyar.client.account.AccountClient) DOWN(java.math.RoundingMode.DOWN) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) MosaicClient(com.github.rosklyar.client.mosaic.MosaicClient) MosaicMetaData(com.github.rosklyar.client.mosaic.domain.MosaicMetaData) MosaicTransfer(com.github.rosklyar.client.transaction.domain.mosaic.MosaicTransfer) BigInteger.valueOf(java.math.BigInteger.valueOf) List(java.util.List) TEN(java.math.BigInteger.TEN) MosaicsMetaDataResponse(com.github.rosklyar.client.mosaic.domain.MosaicsMetaDataResponse) Math(java.lang.Math) DoubleMath.roundToLong(com.google.common.math.DoubleMath.roundToLong) OwnedMosaicsResponse(com.github.rosklyar.client.account.domain.mosaic.OwnedMosaicsResponse) MosaicMetaData(com.github.rosklyar.client.mosaic.domain.MosaicMetaData) MosaicsMetaDataResponse(com.github.rosklyar.client.mosaic.domain.MosaicsMetaDataResponse) OwnedMosaicsResponse(com.github.rosklyar.client.account.domain.mosaic.OwnedMosaicsResponse)

Aggregations

MosaicTransfer (com.github.rosklyar.client.transaction.domain.mosaic.MosaicTransfer)3 NemAnnounceResult (com.github.rosklyar.client.transaction.domain.NemAnnounceResult)2 MosaicId (com.github.rosklyar.client.transaction.domain.mosaic.MosaicId)2 Test (org.junit.jupiter.api.Test)2 AccountClient (com.github.rosklyar.client.account.AccountClient)1 OwnedMosaicsResponse (com.github.rosklyar.client.account.domain.mosaic.OwnedMosaicsResponse)1 MosaicClient (com.github.rosklyar.client.mosaic.MosaicClient)1 MosaicMetaData (com.github.rosklyar.client.mosaic.domain.MosaicMetaData)1 MosaicsMetaDataResponse (com.github.rosklyar.client.mosaic.domain.MosaicsMetaDataResponse)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 DoubleMath.roundToLong (com.google.common.math.DoubleMath.roundToLong)1 Math (java.lang.Math)1 TEN (java.math.BigInteger.TEN)1 BigInteger.valueOf (java.math.BigInteger.valueOf)1 DOWN (java.math.RoundingMode.DOWN)1 List (java.util.List)1