|
|
@@ -11,15 +11,19 @@ import com.crm.rely.backend.core.pojo.table.SysConfigTable;
|
|
|
import com.crm.rely.backend.model.config.VaultodyConfig;
|
|
|
import com.crm.rely.backend.model.constant.ConfigConstants;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.VaultodyVaultsListDto;
|
|
|
-import com.crm.rely.backend.model.dto.vaultody.vaults.response.VaultsListResponseDto;
|
|
|
+import com.crm.rely.backend.model.dto.vaultody.vaults.response.*;
|
|
|
+import com.crm.rely.backend.model.entity.vaultody.vaults.VaultTransactionsEntity;
|
|
|
import com.crm.rely.backend.model.pojo.table.SysVaultodyConfigTable;
|
|
|
import com.crm.rely.backend.util.AESUtil;
|
|
|
import com.crm.rely.backend.util.HttpUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.jsoup.Connection;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.crypto.Mac;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
@@ -194,4 +198,98 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
}
|
|
|
return BaseResultDto.success(dtos);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseResultDto vaultsTransactions(VaultTransactionsEntity entity) throws Exception{
|
|
|
+ String apiKey = "6f3cc6caf513a5cde2df5d3ed805e3703d4d43b2";
|
|
|
+ String apiSecret = "MLjTUAYgxSM2dg=="; // Base64编码的secret
|
|
|
+ String passphrase = "7UGMi2*t0h";
|
|
|
+ String method = "GET";
|
|
|
+ String requestPath = "/vaults/"+entity.getVaultId()+"/transactions";
|
|
|
+ String baseUrl = "https://rest.vaultody.com";
|
|
|
+ String query = "{}";
|
|
|
+ Map<String, String> params = new HashMap();
|
|
|
+ if(!ObjectUtils.isEmpty(entity.getLimit())){
|
|
|
+ params.put("limit", String.valueOf(entity.getLimit()));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(entity.getStartingAfter())){
|
|
|
+ params.put("startingAfter", entity.getStartingAfter());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(entity.getContext())){
|
|
|
+ params.put("context", entity.getContext());
|
|
|
+ }
|
|
|
+ // ------------------ 时间戳(秒) ------------------
|
|
|
+ String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
|
|
+ // ------------------ 构建消息用于签名 ------------------
|
|
|
+ String message = timestamp + method + requestPath + query + JSON.toJSONString(params);
|
|
|
+ String signature = getSignature(message, apiSecret);
|
|
|
+ System.out.println("Signature: " + signature);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("x-api-key", apiKey);
|
|
|
+ headers.put("x-api-sign", signature);
|
|
|
+ headers.put("x-api-timestamp", timestamp);
|
|
|
+ headers.put("x-api-passphrase", passphrase);
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ Connection.Response response = HttpUtil.get(baseUrl + requestPath, headers, params);
|
|
|
+ System.out.println(response.statusCode());
|
|
|
+ System.out.println(response.body());
|
|
|
+ if (response.statusCode() != 200) {
|
|
|
+ return BaseResultDto.error(response.statusMessage());
|
|
|
+ }
|
|
|
+ TransactionResponse responseDto = JSON.parseObject(response.body(), TransactionResponse.class);
|
|
|
+ ResponseData data = responseDto.getData();
|
|
|
+ List<TransactionItem> items;
|
|
|
+ if(CollectionUtils.isEmpty(data.getItems())){
|
|
|
+ items = new ArrayList<>();
|
|
|
+ TransactionItem item = new TransactionItem();
|
|
|
+ item.setBlockchain("ethereum");
|
|
|
+ item.setCreatedTimestamp(System.currentTimeMillis() / 1000);
|
|
|
+ item.setDirection("direction");
|
|
|
+ item.setHasTokenTransfer("false");
|
|
|
+ item.setId("654ba3af9e8dd80901f17347");
|
|
|
+ item.setIsInternal("false");
|
|
|
+ item.setMinedInBlockHeight("1234324");
|
|
|
+ item.setNetwork("mainnet");
|
|
|
+
|
|
|
+ List<TransactionParticipant> recipients = new LinkedList<>();
|
|
|
+ TransactionParticipant recipient = new TransactionParticipant();
|
|
|
+ recipient.setAddress("0xd2070342a1a5ce24930ec6582b3db846458525a0");
|
|
|
+ recipient.setAddressType("deposit");
|
|
|
+ recipient.setAmount("0.0003");
|
|
|
+ recipient.setAmountUnit("ETH");
|
|
|
+ recipient.setIsVaultAddress("false");
|
|
|
+ recipient.setLabel("Address name");
|
|
|
+ recipients.add(recipient);
|
|
|
+
|
|
|
+ List<TransactionParticipant> senders = new LinkedList<>();
|
|
|
+ TransactionParticipant sender = new TransactionParticipant();
|
|
|
+ sender.setAddress("0xa94b8eca8703ad2804cb204976ac023b612c407e");
|
|
|
+ sender.setAddressType("deposit");
|
|
|
+ sender.setAmount("0.0003");
|
|
|
+ sender.setAmountUnit("ETH");
|
|
|
+ sender.setIsVaultAddress("true");
|
|
|
+ sender.setLabel("Address name");
|
|
|
+ senders.add(sender);
|
|
|
+
|
|
|
+
|
|
|
+ item.setRecipients(recipients);
|
|
|
+ item.setSenders(senders);
|
|
|
+
|
|
|
+ item.setStatus("completed");
|
|
|
+ TransactionFee transactionFee = new TransactionFee();
|
|
|
+ transactionFee.setAmount("0.0024");
|
|
|
+ transactionFee.setAmountUnit("ETH");
|
|
|
+ item.setTransactionFee(transactionFee);
|
|
|
+ item.setTransactionId("281a63d28ddf6d0d5d78090b7cdf3a8c0be95bbb296544943ef45d9dec44405d");
|
|
|
+ items.add(item);
|
|
|
+ data.setItems(items);
|
|
|
+ }
|
|
|
+ return BaseResultDto.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TransactionItem> queryExportItems (VaultTransactionsEntity entity) throws Exception{
|
|
|
+ ResponseData result = (ResponseData)vaultsTransactions(entity).getData();
|
|
|
+ return result.getItems();
|
|
|
+ }
|
|
|
}
|