Skip to content

Commit

Permalink
add some operations and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwheeze committed Mar 17, 2024
1 parent 4237d93 commit b7038ec
Show file tree
Hide file tree
Showing 29 changed files with 451 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/DatabaseApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,4 +92,14 @@ public Mono<ApiResponse.ConfigResponse> getConfig() {
return send(DatabaseMethods.getConfig(), ApiResponse.ConfigResponse.class);
}

public Mono<ApiResponse.VestingDelegationResponse> 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);
}

}
28 changes: 28 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/NftApi.java
Original file line number Diff line number Diff line change
@@ -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<NftResponses.GetNftTokenResponse> getNftToken(NftTokenQuery query) {
var method = NftMethods.getNftTokens();
method.getMethodParams()[0] = query;
return send(method, NftResponses.GetNftTokenResponse.class);
}
}
2 changes: 2 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/ApiResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ public static class OpenOrdersResponse extends ApiResponse<List<OpenOrder>> {}
public static class MedianHistoryPriceResponse extends ApiResponse<Price> {};

public static class GetEventsInBlockResponse extends ApiResponse<List<Event>> {};

public static class VestingDelegationResponse extends ApiResponse<List<VestingDelegation>> {};
}
Empty file modified src/main/java/bitwheeze/golos/goloslib/model/Content.java
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/api/NftMethods.java
Original file line number Diff line number Diff line change
@@ -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")
}
}
11 changes: 11 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/nft/NftResponses.java
Original file line number Diff line number Diff line change
@@ -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<List<NftToken>> {};
}
25 changes: 25 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/nft/NftToken.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Empty file.
Empty file modified src/main/java/bitwheeze/golos/goloslib/model/op/Convert.java
100755 → 100644
Empty file.
Empty file.
Empty file.
Empty file modified src/main/java/bitwheeze/golos/goloslib/model/op/Invite.java
100755 → 100644
Empty file.
22 changes: 22 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/op/NftBuy.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/op/NftCollection.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/op/NftIssue.java
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 22 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/op/NftSell.java
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions src/main/java/bitwheeze/golos/goloslib/model/op/NftTransfer.java
Original file line number Diff line number Diff line change
@@ -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;
}
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package bitwheeze.golos.goloslib.types;

public enum DelegationType {
received, delegated;
}
25 changes: 22 additions & 3 deletions src/main/java/bitwheeze/golos/goloslib/utilities/GolosTools.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
}

}
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit b7038ec

Please sign in to comment.