-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for SideChainStakeMigration (#150)
- Loading branch information
1 parent
b6c1b0b
commit cb2e80a
Showing
7 changed files
with
270 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/binance/dex/api/client/domain/stake/sidechain/SideChainStakeMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.binance.dex.api.client.domain.stake.sidechain; | ||
|
||
import com.binance.dex.api.client.encoding.message.Token; | ||
|
||
public class SideChainStakeMigration { | ||
|
||
private String validatorSrcAddr; | ||
|
||
private String validatorDstAddr; | ||
|
||
private String delegatorAddr; | ||
|
||
private String refundAddr; | ||
|
||
private Token amount; | ||
|
||
public SideChainStakeMigration() { | ||
} | ||
|
||
public String getValidatorSrcAddr() { | ||
return validatorSrcAddr; | ||
} | ||
|
||
public void setValidatorSrcAddr(String validatorSrcAddr) { | ||
this.validatorSrcAddr = validatorSrcAddr; | ||
} | ||
|
||
public String getValidatorDstAddr() { | ||
return validatorDstAddr; | ||
} | ||
|
||
public void setValidatorDstAddr(String validatorDstAddr) { | ||
this.validatorDstAddr = validatorDstAddr; | ||
} | ||
|
||
public String getDelegatorAddr() { | ||
return delegatorAddr; | ||
} | ||
|
||
public void setDelegatorAddr(String delegatorAddr) { | ||
this.delegatorAddr = delegatorAddr; | ||
} | ||
|
||
public String getRefundAddr() { | ||
return refundAddr; | ||
} | ||
|
||
public void setRefundAddr(String refundAddr) { | ||
this.refundAddr = refundAddr; | ||
} | ||
|
||
public Token getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(Token amount) { | ||
this.amount = amount; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SideChainStakeMigration{" + | ||
"validatorSrcAddr='" + validatorSrcAddr + '\'' + | ||
", validatorDstAddr='" + validatorDstAddr + '\'' + | ||
", delegatorAddr='" + delegatorAddr + '\'' + | ||
", refundAddr='" + refundAddr + '\'' + | ||
", amount=" + amount + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...dex/api/client/encoding/message/sidechain/transaction/SideChainStakeMigrationMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.binance.dex.api.client.encoding.message.sidechain.transaction; | ||
|
||
import com.binance.dex.api.client.encoding.amino.AminoField; | ||
import com.binance.dex.api.client.encoding.amino.AminoSerializable; | ||
import com.binance.dex.api.client.encoding.message.BinanceDexTransactionMessage; | ||
import com.binance.dex.api.client.encoding.message.common.Bech32AddressValue; | ||
import com.binance.dex.api.client.encoding.message.common.CoinValueStr; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.ArrayList; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonPropertyOrder(alphabetic = true) | ||
public class SideChainStakeMigrationMessage implements BinanceDexTransactionMessage, AminoSerializable { | ||
|
||
@JsonProperty(value = "validator_src_addr") | ||
private Bech32AddressValue validatorSrcAddr; | ||
|
||
@JsonProperty(value = "validator_dst_addr") | ||
private byte[] validatorDstAddr; | ||
|
||
@JsonProperty(value = "delegator_addr") | ||
private byte[] delegatorAddr; | ||
|
||
@JsonProperty(value = "refund_addr") | ||
private Bech32AddressValue refundAddr; | ||
|
||
@JsonProperty(value = "amount") | ||
private CoinValueStr amount; | ||
|
||
public SideChainStakeMigrationMessage() { | ||
} | ||
|
||
@Override | ||
public AminoSerializable newAminoMessage() { | ||
return new SideChainStakeMigrationMessage(); | ||
} | ||
|
||
@Override | ||
public ArrayList<AminoField<?>> IterateFields() { | ||
return AminoField.newFieldsBuilder() | ||
.addField(Bech32AddressValue.class, validatorSrcAddr, validatorSrcAddr == null || validatorSrcAddr.isDefaultOrEmpty()) | ||
.addField(byte[].class, validatorDstAddr, validatorDstAddr == null || validatorDstAddr.length == 0) | ||
.addField(byte[].class, delegatorAddr, delegatorAddr == null || delegatorAddr.length == 0) | ||
.addField(Bech32AddressValue.class, refundAddr, refundAddr == null || refundAddr.isDefaultOrEmpty()) | ||
.addField(CoinValueStr.class, amount, amount == null) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void setValueByFieldIndex(int fieldIndex, Object value) { | ||
switch (fieldIndex) { | ||
case 1: | ||
validatorSrcAddr = ((Bech32AddressValue) value); | ||
break; | ||
case 2: | ||
validatorDstAddr = ((byte[]) value); | ||
break; | ||
case 3: | ||
delegatorAddr = ((byte[]) value); | ||
break; | ||
case 4: | ||
refundAddr = ((Bech32AddressValue) value); | ||
break; | ||
case 5: | ||
amount = ((CoinValueStr) value); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean useAminoJson() { | ||
return true; | ||
} | ||
|
||
public Bech32AddressValue getValidatorSrcAddr() { | ||
return validatorSrcAddr; | ||
} | ||
|
||
public void setValidatorSrcAddr(Bech32AddressValue validatorSrcAddr) { | ||
this.validatorSrcAddr = validatorSrcAddr; | ||
} | ||
|
||
public byte[] getValidatorDstAddr() { | ||
return validatorDstAddr; | ||
} | ||
|
||
public void setValidatorDstAddr(byte[] validatorDstAddr) { | ||
this.validatorDstAddr = validatorDstAddr; | ||
} | ||
|
||
public byte[] getDelegatorAddr() { | ||
return delegatorAddr; | ||
} | ||
|
||
public void setDelegatorAddr(byte[] delegatorAddr) { | ||
this.delegatorAddr = delegatorAddr; | ||
} | ||
|
||
public Bech32AddressValue getRefundAddr() { | ||
return refundAddr; | ||
} | ||
|
||
public void setRefundAddr(Bech32AddressValue refundAddr) { | ||
this.refundAddr = refundAddr; | ||
} | ||
|
||
public CoinValueStr getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(CoinValueStr amount) { | ||
this.amount = amount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...va/com/binance/dex/api/client/utils/converter/impl/FSideChainStakeMigrationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.binance.dex.api.client.utils.converter.impl; | ||
|
||
import com.binance.dex.api.client.domain.Transaction; | ||
import com.binance.dex.api.client.domain.TransactionV2; | ||
import com.binance.dex.api.client.domain.broadcast.TxType; | ||
import com.binance.dex.api.client.domain.stake.sidechain.SideChainRedelegate; | ||
import com.binance.dex.api.client.domain.stake.sidechain.SideChainStakeMigration; | ||
import com.binance.dex.api.client.utils.converter.JsonUtil; | ||
import com.binance.dex.api.client.utils.converter.NumberUtil; | ||
import com.binance.dex.api.client.utils.converter.Token; | ||
import com.binance.dex.api.client.utils.converter.TransactionConverter; | ||
|
||
import java.util.Map; | ||
|
||
public class FSideChainStakeMigrationConverter extends TransactionConverter<SideChainStakeMigration> { | ||
|
||
@Override | ||
public TxType getType() { | ||
return TxType.SIDECHAIN_STAKE_MIGRATION; | ||
} | ||
|
||
@Override | ||
public void doConvert(TransactionV2 transactionV2, Transaction transaction) { | ||
transaction.setValue(NumberUtil.longToBigDecimalString(transactionV2.getAmount())); | ||
|
||
Map<String, Object> map = JsonUtil.fromJson(transactionV2.getData(), Map.class); | ||
if (transaction.getValue() == null || transaction.getTxAsset() == null) { | ||
Token token = getToken(map, "amount"); | ||
transaction.setTxAsset(token.getDenom()); | ||
transaction.setValue(NumberUtil.longToBigDecimalString(token.getAmount())); | ||
} | ||
} | ||
} |