diff --git a/src/main/java/bitwheeze/golos/goloslib/DatabaseApi.java b/src/main/java/bitwheeze/golos/goloslib/DatabaseApi.java index 510f4ce..b25b174 100644 --- a/src/main/java/bitwheeze/golos/goloslib/DatabaseApi.java +++ b/src/main/java/bitwheeze/golos/goloslib/DatabaseApi.java @@ -6,6 +6,7 @@ import bitwheeze.golos.goloslib.model.Transaction; import bitwheeze.golos.goloslib.model.api.DatabaseMethods; import bitwheeze.golos.goloslib.model.api.NetworkBroadcastMethods; +import bitwheeze.golos.goloslib.types.DelegationType; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @@ -91,4 +92,14 @@ public Mono getConfig() { return send(DatabaseMethods.getConfig(), ApiResponse.ConfigResponse.class); } + public Mono getVestingDelegations(String account, String from, Integer limit, DelegationType type) { + var method = DatabaseMethods.getVestingDelegations(); + method.getMethodParams()[0] = account; + method.getMethodParams()[1] = Optional.ofNullable(from).orElse("");; + method.getMethodParams()[2] = Optional.ofNullable(limit).orElse(10); + method.getMethodParams()[3] = type; + + return send(method, ApiResponse.VestingDelegationResponse.class); + } + } diff --git a/src/main/java/bitwheeze/golos/goloslib/NftApi.java b/src/main/java/bitwheeze/golos/goloslib/NftApi.java new file mode 100644 index 0000000..70f7ed3 --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/NftApi.java @@ -0,0 +1,28 @@ +package bitwheeze.golos.goloslib; + +import bitwheeze.golos.goloslib.model.ApiResponse; +import bitwheeze.golos.goloslib.model.api.MarketHistoryMethods; +import bitwheeze.golos.goloslib.model.api.NftMethods; +import bitwheeze.golos.goloslib.model.nft.NftResponses; +import bitwheeze.golos.goloslib.model.nft.NftTokenQuery; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@Slf4j +@Component +public class NftApi extends GolosApiReactive { + + + public NftApi(@Qualifier("golos_api") WebClient client) { + super(client); + } + + public Mono getNftToken(NftTokenQuery query) { + var method = NftMethods.getNftTokens(); + method.getMethodParams()[0] = query; + return send(method, NftResponses.GetNftTokenResponse.class); + } +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/ApiResponse.java b/src/main/java/bitwheeze/golos/goloslib/model/ApiResponse.java index 7cdb39b..208958e 100644 --- a/src/main/java/bitwheeze/golos/goloslib/model/ApiResponse.java +++ b/src/main/java/bitwheeze/golos/goloslib/model/ApiResponse.java @@ -83,4 +83,6 @@ public static class OpenOrdersResponse extends ApiResponse> {} public static class MedianHistoryPriceResponse extends ApiResponse {}; public static class GetEventsInBlockResponse extends ApiResponse> {}; + + public static class VestingDelegationResponse extends ApiResponse> {}; } diff --git a/src/main/java/bitwheeze/golos/goloslib/model/Content.java b/src/main/java/bitwheeze/golos/goloslib/model/Content.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/VestingDelegation.java b/src/main/java/bitwheeze/golos/goloslib/model/VestingDelegation.java new file mode 100644 index 0000000..bb8e212 --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/VestingDelegation.java @@ -0,0 +1,20 @@ +package bitwheeze.golos.goloslib.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.ToString; + +import java.time.LocalDateTime; + +@Data +@ToString +public class VestingDelegation { + int id; //: 195170, + String delegator;// ": "prizm", + String delegatee;// ": "payme", + Asset vestingShares; //": "8619571271.824690 GESTS", + int interestRate; //": 10000, + LocalDateTime minDelegationTime; //": "2024-02-25T13:00:09", + @JsonProperty("is_emission") + boolean isEmission; //": true +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/api/DatabaseMethods.java b/src/main/java/bitwheeze/golos/goloslib/model/api/DatabaseMethods.java index af49540..10d75b9 100644 --- a/src/main/java/bitwheeze/golos/goloslib/model/api/DatabaseMethods.java +++ b/src/main/java/bitwheeze/golos/goloslib/model/api/DatabaseMethods.java @@ -12,6 +12,7 @@ public class DatabaseMethods extends ApiMethod { public static ApiMethod getAssets() {return new DatabaseMethods("get_assets", 5);}; public static ApiMethod getChainProperties() {return new DatabaseMethods("get_chain_properties", 0);}; public static ApiMethod getConfig() {return new DatabaseMethods("get_config", 0);}; + public static ApiMethod getVestingDelegations() {return new DatabaseMethods("get_vesting_delegations", 4);}; public DatabaseMethods(String method, String [] paramNames) { diff --git a/src/main/java/bitwheeze/golos/goloslib/model/api/NftMethods.java b/src/main/java/bitwheeze/golos/goloslib/model/api/NftMethods.java new file mode 100644 index 0000000..d052f1d --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/api/NftMethods.java @@ -0,0 +1,17 @@ +package bitwheeze.golos.goloslib.model.api; + + +public class NftMethods extends ApiMethod { + + public static NftMethods getNftTokens() {return new NftMethods("get_nft_tokens", new String[]{"query"});}; + + + public NftMethods(String method, String [] paramNames) { + + super("nft_api", method, paramNames); + } + + public static void main(String[] args) { + //ApiRequest req = new ApiRequest("database_api", "get_dynamic_global_properties") + } +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/nft/NftResponses.java b/src/main/java/bitwheeze/golos/goloslib/model/nft/NftResponses.java new file mode 100644 index 0000000..d93a06d --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/nft/NftResponses.java @@ -0,0 +1,11 @@ +package bitwheeze.golos.goloslib.model.nft; + +import bitwheeze.golos.goloslib.model.ApiResponse; +import bitwheeze.golos.goloslib.model.op.virtual.Event; + +import java.util.List; + +public class NftResponses { + + public static class GetNftTokenResponse extends ApiResponse> {}; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/nft/NftToken.java b/src/main/java/bitwheeze/golos/goloslib/model/nft/NftToken.java new file mode 100644 index 0000000..464f349 --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/nft/NftToken.java @@ -0,0 +1,25 @@ +package bitwheeze.golos.goloslib.model.nft; + +import bitwheeze.golos.goloslib.model.Asset; +import lombok.Data; +import lombok.ToString; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@ToString +public class NftToken { + String id; + String creator; + String name; + String owner; + int token_id; + Asset issueCost; + Asset lastBuyPrice; + String jsonMetadata; + LocalDateTime issued; + LocalDateTime lastUpdate; + boolean selling; + BigDecimal priceReal; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/nft/NftTokenQuery.java b/src/main/java/bitwheeze/golos/goloslib/model/nft/NftTokenQuery.java new file mode 100644 index 0000000..c337ddd --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/nft/NftTokenQuery.java @@ -0,0 +1,50 @@ +package bitwheeze.golos.goloslib.model.nft; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.ToString; + +@Data +@Builder +@ToString +@JsonInclude(JsonInclude.Include.NON_NULL) +public class NftTokenQuery { + String owner; + @JsonProperty("start_token_id") + Integer startTokenId; + Integer limit; // принцип работы пагинации описан на примере getNftCollections + + @JsonProperty("select_collections") + String[] selectCollections; // выбирает токены из заданных коллекций + @JsonProperty("collections_limit") + Integer collectionLimit; // Например - чтобы в списке коллекций (getNftCollections) добавить к каждой коллекции информацию о первом токене в ней + + @JsonProperty("select_token_ids") + Integer[] selectTokenIds; // выборка конкретных токенов + + @JsonProperty("filter_creators") + String[] filterCreators; + + @JsonProperty("filter_token_ids") + Integer[] filterTokenIds; + + @JsonProperty("filter_names") + String [] filterNames; // игнорировать токены из этих коллекций + + public enum TokenState { + any, selling_one, not_selling_one; + } + + TokenState state; // или 'selling_one' - только токены которые выставлены на продажу, или 'not_selling_one' - только которые не выставлены + + public enum TokenSortOrder { + by_name, by_issued, by_last_update, by_last_price; + } + + TokenSortOrder sort; // by_issued, by_last_update, by_last_price + @JsonProperty("reverse_sort") + Boolean reverseSort; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/AccountCreateWithInvite.java b/src/main/java/bitwheeze/golos/goloslib/model/op/AccountCreateWithInvite.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/Convert.java b/src/main/java/bitwheeze/golos/goloslib/model/op/Convert.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/DelegateVestingSharesWithInterest.java b/src/main/java/bitwheeze/golos/goloslib/model/op/DelegateVestingSharesWithInterest.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/DeleteComment.java b/src/main/java/bitwheeze/golos/goloslib/model/op/DeleteComment.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/Invite.java b/src/main/java/bitwheeze/golos/goloslib/model/op/Invite.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/NftBuy.java b/src/main/java/bitwheeze/golos/goloslib/model/op/NftBuy.java new file mode 100644 index 0000000..9916ad2 --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/op/NftBuy.java @@ -0,0 +1,22 @@ +package bitwheeze.golos.goloslib.model.op; + +import bitwheeze.golos.goloslib.model.Asset; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +@JsonDeserialize(using = JsonDeserializer.None.class) +@OpName("nft_buy") +@AllArgsConstructor +public class NftBuy extends Operation { + private String buyer; + private String name; + private int tokenId; + private int orderId; + private Asset price; + private String[] extensions; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/NftCancelOrder.java b/src/main/java/bitwheeze/golos/goloslib/model/op/NftCancelOrder.java new file mode 100644 index 0000000..23f329f --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/op/NftCancelOrder.java @@ -0,0 +1,19 @@ +package bitwheeze.golos.goloslib.model.op; + +import bitwheeze.golos.goloslib.model.Asset; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +@JsonDeserialize(using = JsonDeserializer.None.class) +@OpName("nft_cancel_order") +@AllArgsConstructor +public class NftCancelOrder extends Operation { + private String owner; + private int orderId; + private String[] extensions; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/NftCollection.java b/src/main/java/bitwheeze/golos/goloslib/model/op/NftCollection.java new file mode 100644 index 0000000..34e4fba --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/op/NftCollection.java @@ -0,0 +1,21 @@ +package bitwheeze.golos.goloslib.model.op; + +import bitwheeze.golos.goloslib.model.Asset; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +@JsonDeserialize(using = JsonDeserializer.None.class) +@OpName("nft_collection") +@AllArgsConstructor +public class NftCollection extends Operation { + private String creator; + private String name; + private String jsonMetadata; + private int maxTokenCount; + private String[] extensions; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/NftCollectionDelete.java b/src/main/java/bitwheeze/golos/goloslib/model/op/NftCollectionDelete.java new file mode 100644 index 0000000..120b08c --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/op/NftCollectionDelete.java @@ -0,0 +1,18 @@ +package bitwheeze.golos.goloslib.model.op; + +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +@JsonDeserialize(using = JsonDeserializer.None.class) +@OpName("nft_collection_delete") +@AllArgsConstructor +public class NftCollectionDelete extends Operation { + private String creator; + private String name; + private String[] extensions; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/NftIssue.java b/src/main/java/bitwheeze/golos/goloslib/model/op/NftIssue.java new file mode 100644 index 0000000..6889bee --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/op/NftIssue.java @@ -0,0 +1,20 @@ +package bitwheeze.golos.goloslib.model.op; + +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +@JsonDeserialize(using = JsonDeserializer.None.class) +@OpName("nft_issue") +@AllArgsConstructor +public class NftIssue extends Operation { + private String creator; + private String name; + private String to; + private String jsonMetadata; + private String[] extensions; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/NftSell.java b/src/main/java/bitwheeze/golos/goloslib/model/op/NftSell.java new file mode 100644 index 0000000..767a731 --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/op/NftSell.java @@ -0,0 +1,22 @@ +package bitwheeze.golos.goloslib.model.op; + +import bitwheeze.golos.goloslib.model.Asset; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +@JsonDeserialize(using = JsonDeserializer.None.class) +@OpName("nft_sell") +@AllArgsConstructor +public class NftSell extends Operation { + private String seller; + private int tokenId; + private String buyer; + private int orderId; + private Asset price; + private String[] extensions; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/NftTransfer.java b/src/main/java/bitwheeze/golos/goloslib/model/op/NftTransfer.java new file mode 100644 index 0000000..be33178 --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/model/op/NftTransfer.java @@ -0,0 +1,20 @@ +package bitwheeze.golos.goloslib.model.op; + +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +@JsonDeserialize(using = JsonDeserializer.None.class) +@OpName("nft_transfer") +@AllArgsConstructor +public class NftTransfer extends Operation { + private int tokenId; + private String from; + private String to; + private String memo; + private String[] extensions; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/TransferToVesting.java b/src/main/java/bitwheeze/golos/goloslib/model/op/TransferToVesting.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/WithdrawVesting.java b/src/main/java/bitwheeze/golos/goloslib/model/op/WithdrawVesting.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/model/op/WithnessUpdate.java b/src/main/java/bitwheeze/golos/goloslib/model/op/WithnessUpdate.java old mode 100755 new mode 100644 diff --git a/src/main/java/bitwheeze/golos/goloslib/types/DelegationType.java b/src/main/java/bitwheeze/golos/goloslib/types/DelegationType.java new file mode 100644 index 0000000..7ff74d7 --- /dev/null +++ b/src/main/java/bitwheeze/golos/goloslib/types/DelegationType.java @@ -0,0 +1,5 @@ +package bitwheeze.golos.goloslib.types; + +public enum DelegationType { + received, delegated; +} diff --git a/src/main/java/bitwheeze/golos/goloslib/utilities/GolosTools.java b/src/main/java/bitwheeze/golos/goloslib/utilities/GolosTools.java index a714c87..4e83d71 100644 --- a/src/main/java/bitwheeze/golos/goloslib/utilities/GolosTools.java +++ b/src/main/java/bitwheeze/golos/goloslib/utilities/GolosTools.java @@ -1,11 +1,11 @@ package bitwheeze.golos.goloslib.utilities; -import bitwheeze.golos.goloslib.model.Account; -import bitwheeze.golos.goloslib.model.ChainProperties; -import bitwheeze.golos.goloslib.model.Config; +import bitwheeze.golos.goloslib.model.*; import bitwheeze.golos.goloslib.types.ChainTypes; import lombok.extern.slf4j.Slf4j; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDateTime; import java.time.ZoneOffset; @@ -32,4 +32,23 @@ public static long calcSecondsTillFullRegenerated(Account account, Config config var current_power = calcCurrentVotePower(account, config); return config.getSteemitVoteRegenerationSeconds() * (long)(config.getSteemit100Percent() - current_power) / config.getSteemit100Percent(); } + + public static BigDecimal calcEmissionPerDay(BigDecimal vestingShares, DynamicGlobalProperties props) { + var total = props.getTotalVestingShares().getValue(); + var acc = convertGolosToVestings(props.getAccumulativeEmissionPerDay().getValue(), props); + return acc.multiply(vestingShares).divide(total, RoundingMode.HALF_DOWN).setScale(6, RoundingMode.DOWN); + } + + public static BigDecimal convertVestingsToGolos(BigDecimal vestings, DynamicGlobalProperties props) { + var totalVestings = props.getTotalVestingShares().getValue(); + var totalGolos = props.getTotalVestingFundSteem().getValue(); + return totalGolos.multiply(vestings).divide(totalVestings, RoundingMode.HALF_DOWN).setScale(3, RoundingMode.DOWN); + } + + public static BigDecimal convertGolosToVestings(BigDecimal golos, DynamicGlobalProperties props) { + var totalVestings = props.getTotalVestingShares().getValue(); + var totalGolos = props.getTotalVestingFundSteem().getValue(); + return totalVestings.multiply(golos).divide(totalGolos, RoundingMode.HALF_DOWN).setScale(6, RoundingMode.DOWN); + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b41bb1b..934e5a3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ #spring.main.web-environment=false #spring.main.web-application-type=NONE -#golos.api=https://apibeta.golos.today -golos.api=https://api-full.golos.id +golos.api=https://apibeta.golos.today +#golos.api=https://api-full.golos.id golos.media-type=application/json #golos.api=http://localhost:8090 #golos.media-type=application/octet-stream diff --git a/src/test/java/bitwheeze/golos/goloslib/GolosApiTest.java b/src/test/java/bitwheeze/golos/goloslib/GolosApiTest.java index 0e6a197..991077f 100644 --- a/src/test/java/bitwheeze/golos/goloslib/GolosApiTest.java +++ b/src/test/java/bitwheeze/golos/goloslib/GolosApiTest.java @@ -1,7 +1,19 @@ package bitwheeze.golos.goloslib; +import bitwheeze.golos.goloslib.model.VestingDelegation; import bitwheeze.golos.goloslib.model.exception.BlockchainError; +import bitwheeze.golos.goloslib.model.nft.NftToken; +import bitwheeze.golos.goloslib.model.nft.NftTokenQuery; +import bitwheeze.golos.goloslib.model.op.NftCollection; +import bitwheeze.golos.goloslib.model.op.NftCollectionDelete; +import bitwheeze.golos.goloslib.model.op.NftIssue; +import bitwheeze.golos.goloslib.model.op.NftTransfer; +import bitwheeze.golos.goloslib.types.DelegationType; import bitwheeze.golos.goloslib.utilities.GolosTools; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.Builder; +import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; @@ -11,8 +23,10 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.util.Assert; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; +import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; @@ -29,6 +43,10 @@ class GolosApiTest { @Autowired private WitnessApi witness; @Autowired private EventApi eventApi; @Autowired private NetworkBroadcastApi netApi; + @Autowired private NftApi nftApi; + + private static final String POSTING_WIF = "5HwQScueMZdELZpjVBD4gm6xhiKiMqGx18g4WtQ6wVr4nBdSxY5"; + private static final String ACTIVE_WIF = "5K67PNheLkmxkgJ5UjvR8Nyt3GVPoLEN1dMZjFuNETzrNyMecPG"; @Test void getDynamicGlobalProperties() { @@ -91,7 +109,7 @@ void getAccountsStringList() { void getOpsInBlock() { final long TEST_BLOCK_NUM = 52518042; var ops = history.getOpsInBlock(TEST_BLOCK_NUM, false).block().orElseThrow(); - assertFalse(ops.isEmpty()); + //assertFalse(ops.isEmpty()); } @Test @@ -141,6 +159,80 @@ void badTransaction() { } + @Test + void createNftCollection() throws JsonProcessingException { + @Data + class CollectionDesc { + String desc = "Medal of Honor"; + String app = "lexicon"; + } + + //{"hero":"Canon the Barbarian","desc":"Рубит всех своим мечем налево и на право","type":"legendary","health":120,"str":100,"defence":40,"mana":10,"consumes":"red,blue"} + @Data + class TokenDesc { + String id = UUID.randomUUID().toString(); + String title = "Canon the Barbarian"; + String description = "Рубит всех своим мечем налево и на право"; + String image = "https://devimages.golos.today/0x0/https://steemitimages.com/0x0/https://i.imgur.com/V1pnpH8.png"; + String type = "legendary"; + int health = 120; + int strength = 100; + int defence = 40; + int mana = 10; + String [] consumes = new String[] {"red", "blue"}; + } + + @Data + class Medal { + String id = UUID.randomUUID().toString(); + String title = "Speedy Gonzales"; + String description = "Значок отличника раскладывания пасьянса. Самый быстрый расклад. Владелец этого значка может разово вернуть сделанную ставку."; + String image = "https://devimages.golos.today/0x0/https://steemitimages.com/0x0/https://i.imgur.com/1RzAWCi.jpg"; + String type = "legendary"; + } + + var tr = transactionFactory + .getBuidler() + .add(new NftCollection("travian", "GOLOS.BACKERS", new ObjectMapper().writeValueAsString(new CollectionDesc()), 1000, new String[0])) + .buildAndSign(new String[] {ACTIVE_WIF}); + netApi.broadcastTransaction(tr).block().orElseThrow(); + + var tr1 = transactionFactory + .getBuidler() + .add(new NftIssue("travian", "GOLOS.BACKERS", "travian", new ObjectMapper().writeValueAsString(new TokenDesc()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "travian", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "travian", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "travian", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "travian", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "lex", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "travian", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .add(new NftIssue("travian", "GOLOS.BACKERS", "travian", new ObjectMapper().writeValueAsString(new Medal()), new String[0])) + .buildAndSign(new String[]{ACTIVE_WIF}); + netApi.broadcastTransaction(tr1).block().orElseThrow(); + + + List tokens = nftApi.getNftToken(NftTokenQuery.builder().owner("lex").limit(100).build()).block().orElseThrow(); + log.info("tokens size {}", tokens.size()); + tokens.forEach(t -> log.info("token {}", t)); + { + tr = transactionFactory + .getBuidler() + .add(new NftCollectionDelete("lex", "GOLOS.BACKER", new String[0])) + .buildAndSign(new String[] {ACTIVE_WIF}); + netApi.broadcastTransaction(tr).block().orElseThrow(); + } + + } + @Test void getContent() { var content = social.getContent("bitwheeze", "volya", 0, 0).block().orElseThrow(); @@ -212,7 +304,29 @@ void getConfig() { } + @Test void getEmission() { + var props = api.getDynamicGlobalProperties().block().orElseThrow(); + log.info("conversion rate {}", GolosTools.convertGolosToVestings(BigDecimal.ONE, props)); + log.info("conversion rate {}", GolosTools.convertVestingsToGolos(GolosTools.convertGolosToVestings(BigDecimal.ONE, props), props)); + var delegatedVestings = api.getVestingDelegations("bitwheeze", "ramin", 100, DelegationType.received).block().orElseThrow(); + var received = delegatedVestings.stream() + .peek(d -> log.info("received delelgation {}", d)) + .filter(VestingDelegation::isEmission) + .map(d -> d.getVestingShares().getValue()) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + + log.info("receved with emission {}", received); + log.info("emission per day total = {}", props.getAccumulativeEmissionPerDay()); + if(received.compareTo(BigDecimal.ZERO) > 0) { + var emission = GolosTools.calcEmissionPerDay(received, props); + log.info("Emission per day from Prizm = {}", GolosTools.convertVestingsToGolos(emission, props)); + + } + } + @SpringBootApplication static class TestConfiguration { } + } \ No newline at end of file