use of com.google.protobuf2.Any in project cosmostation-android by cosmostation.
the class Signer method getKavaIncentiveSwap.
public static Any getKavaIncentiveSwap(String sender, ArrayList<kava.incentive.v1beta1.Tx.Selection> denoms_to_claims) {
kava.incentive.v1beta1.Tx.MsgClaimSwapReward msgClaimSwapReward = kava.incentive.v1beta1.Tx.MsgClaimSwapReward.newBuilder().setSender(sender).addAllDenomsToClaim(denoms_to_claims).build();
Any msgKavaClaimSwapAny = Any.newBuilder().setTypeUrl("/kava.incentive.v1beta1.MsgClaimSwapReward").setValue(msgClaimSwapReward.toByteString()).build();
return msgKavaClaimSwapAny;
}
use of com.google.protobuf2.Any in project cosmostation-android by cosmostation.
the class Signer method getStartLockMsg.
public static ArrayList<Any> getStartLockMsg(QueryOuterClass.QueryAccountResponse auth, long duration, Coin lpCoin) {
ArrayList<Any> msgAnys = new ArrayList<>();
CoinOuterClass.Coin lockupCoin = CoinOuterClass.Coin.newBuilder().setDenom(lpCoin.denom).setAmount(lpCoin.amount).build();
ArrayList<CoinOuterClass.Coin> lockupTokens = new ArrayList<>();
lockupTokens.add(lockupCoin);
Duration OsmoDuration = Duration.newBuilder().setSeconds(duration).setNanos(0).build();
osmosis.lockup.Tx.MsgLockTokens msgLockTokens = osmosis.lockup.Tx.MsgLockTokens.newBuilder().setOwner(onParseAddress(auth)).setDuration(OsmoDuration).addAllCoins(lockupTokens).build();
msgAnys.add(Any.newBuilder().setTypeUrl("/osmosis.lockup.MsgLockTokens").setValue(msgLockTokens.toByteString()).build());
return msgAnys;
}
use of com.google.protobuf2.Any in project OpenAM by OpenRock.
the class SecureLogHelperJSSImpl method readFromSecretStore.
/**
* Returns matched secret data from from the secret Storage.
* At a time there are only 3 things in logger's secure store file
* - initialkey, currentkey and current signature
* In the verifier secure store file there is just the initial key of the
* logger and the currentKey
* @param filename file for secret storage
* @param dataType The kind of data to be read, whether it is a
* signature or a key
* @param password password for the file
* @return secure data that is matched with dataType
* @throws Exception if it fails to read secret data from secret store
*/
byte[] readFromSecretStore(String filename, String dataType, AMPassword password) throws Exception {
// open input file for reading
FileInputStream infile = null;
infile = new FileInputStream(filename);
// Decode the P12 file
PFX.Template pfxt = new PFX.Template();
PFX pfx = (PFX) pfxt.decode(new BufferedInputStream(infile, 2048));
// Verify the MAC on the PFX. This is important to be sure
// it hasn't been tampered with.
StringBuffer reason = new StringBuffer();
MessageDigest md = MessageDigest.getInstance("SHA");
Password jssPasswd = new Password(new String(md.digest(password.getByteCopy()), "UTF-8").toCharArray());
md.reset();
if (!pfx.verifyAuthSafes(jssPasswd, reason)) {
throw new Exception("AuthSafes failed to verify because: " + reason.toString());
}
AuthenticatedSafes authSafes = pfx.getAuthSafes();
SEQUENCE safeContentsSequence = authSafes.getSequence();
byte[] cryptoData = null;
// Loop over contents of the authenticated safes
for (int i = 0; i < safeContentsSequence.size(); i++) {
// The safeContents may or may not be encrypted. We always send
// the password in. It will get used if it is needed. If the
// decryption of the safeContents fails for some reason (like
// a bad password), then this method will throw an exception
SEQUENCE safeContents = authSafes.getSafeContentsAt(jssPasswd, i);
SafeBag safeBag = null;
ASN1Value val = null;
// Go through all the bags in this SafeContents
for (int j = 0; j < safeContents.size(); j++) {
safeBag = (SafeBag) safeContents.elementAt(j);
// look for bag attributes and then choose the key
SET attribs = safeBag.getBagAttributes();
if (attribs == null) {
Debug.error("Bag has no attributes");
} else {
for (int b = 0; b < attribs.size(); b++) {
Attribute a = (Attribute) attribs.elementAt(b);
if (a.getType().equals(SafeBag.FRIENDLY_NAME)) {
// the friendly name attribute is a nickname
BMPString bs = (BMPString) ((ANY) a.getValues().elementAt(0)).decodeWith(BMPString.getTemplate());
if (dataType.equals(bs.toString())) {
// look at the contents of the bag
val = safeBag.getInterpretedBagContent();
break;
}
}
}
}
}
if (val instanceof ANY)
cryptoData = ((ANY) val).getContents();
}
// Close the file
infile.close();
return cryptoData;
}
use of com.google.protobuf2.Any in project cosmostation-android by cosmostation.
the class WUtil method onParseVestingAccount.
// parse & check vesting account
public static void onParseVestingAccount(BaseData baseData, BaseChain baseChain) {
WLog.w("onParseVestingAccount");
Any account = baseData.mGRpcAccount;
if (account == null)
return;
ArrayList<Coin> sBalace = new ArrayList<>();
for (Coin coin : baseData.mGrpcBalance) {
sBalace.add(coin);
}
if (account.getTypeUrl().contains(Vesting.PeriodicVestingAccount.getDescriptor().getFullName())) {
Vesting.PeriodicVestingAccount vestingAccount = null;
try {
vestingAccount = Vesting.PeriodicVestingAccount.parseFrom(account.getValue());
} catch (InvalidProtocolBufferException e) {
WLog.e("onParseVestingAccount " + e.getMessage());
return;
}
for (Coin coin : sBalace) {
String denom = coin.denom;
BigDecimal dpBalance = BigDecimal.ZERO;
BigDecimal dpVesting = BigDecimal.ZERO;
BigDecimal originalVesting = BigDecimal.ZERO;
BigDecimal remainVesting = BigDecimal.ZERO;
BigDecimal delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
WLog.w("dpBalance " + denom + " " + dpBalance);
for (CoinOuterClass.Coin vesting : vestingAccount.getBaseVestingAccount().getOriginalVestingList()) {
if (vesting.getDenom().equals(denom)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.getAmount()));
}
}
WLog.w("originalVesting " + denom + " " + originalVesting);
for (CoinOuterClass.Coin vesting : vestingAccount.getBaseVestingAccount().getDelegatedVestingList()) {
if (vesting.getDenom().equals(denom)) {
delegatedVesting = delegatedVesting.add(new BigDecimal(vesting.getAmount()));
}
}
WLog.w("delegatedVesting " + denom + " " + delegatedVesting);
remainVesting = WDp.onParsePeriodicRemainVestingsAmountByDenom(vestingAccount, denom);
WLog.w("remainVesting " + denom + " " + remainVesting);
dpVesting = remainVesting.subtract(delegatedVesting);
WLog.w("dpVestingA " + denom + " " + dpVesting);
dpVesting = dpVesting.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : dpVesting;
WLog.w("dpVestingB " + denom + " " + dpVesting);
if (remainVesting.compareTo(delegatedVesting) > 0) {
dpBalance = dpBalance.subtract(remainVesting).add(delegatedVesting);
}
WLog.w("final dpBalance " + denom + " " + dpBalance);
if (dpVesting.compareTo(BigDecimal.ZERO) > 0) {
Coin vestingCoin = new Coin(denom, dpVesting.toPlainString());
baseData.mGrpcVesting.add(vestingCoin);
int replace = -1;
for (int i = 0; i < baseData.mGrpcBalance.size(); i++) {
if (baseData.mGrpcBalance.get(i).denom.equals(denom)) {
replace = i;
}
}
if (replace >= 0) {
baseData.mGrpcBalance.set(replace, new Coin(denom, dpBalance.toPlainString()));
}
}
}
} else if (account.getTypeUrl().contains(Vesting.ContinuousVestingAccount.getDescriptor().getFullName())) {
Vesting.ContinuousVestingAccount vestingAccount = null;
try {
vestingAccount = Vesting.ContinuousVestingAccount.parseFrom(account.getValue());
} catch (InvalidProtocolBufferException e) {
WLog.e("onParseVestingAccount " + e.getMessage());
return;
}
for (Coin coin : sBalace) {
String denom = coin.denom;
BigDecimal dpBalance = BigDecimal.ZERO;
BigDecimal dpVesting = BigDecimal.ZERO;
BigDecimal originalVesting = BigDecimal.ZERO;
BigDecimal remainVesting = BigDecimal.ZERO;
BigDecimal delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
WLog.w("dpBalance " + denom + " " + dpBalance);
for (CoinOuterClass.Coin vesting : vestingAccount.getBaseVestingAccount().getOriginalVestingList()) {
if (vesting.getDenom().equals(denom)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.getAmount()));
}
}
WLog.w("originalVesting " + denom + " " + originalVesting);
for (CoinOuterClass.Coin vesting : vestingAccount.getBaseVestingAccount().getDelegatedVestingList()) {
if (vesting.getDenom().equals(denom)) {
delegatedVesting = delegatedVesting.add(new BigDecimal(vesting.getAmount()));
}
}
WLog.w("delegatedVesting " + denom + " " + delegatedVesting);
long cTime = Calendar.getInstance().getTime().getTime();
long vestingStart = vestingAccount.getStartTime() * 1000;
long vestingEnd = vestingAccount.getBaseVestingAccount().getEndTime() * 1000;
if (cTime < vestingStart) {
remainVesting = originalVesting;
} else if (cTime > vestingEnd) {
remainVesting = BigDecimal.ZERO;
} else if (cTime < vestingEnd) {
float progress = ((float) (cTime - vestingStart) / (float) (vestingEnd - vestingStart));
remainVesting = originalVesting.multiply(new BigDecimal(1 - progress)).setScale(0, RoundingMode.UP);
}
WLog.w("remainVesting " + denom + " " + remainVesting);
dpVesting = remainVesting.subtract(delegatedVesting);
WLog.w("dpVestingA " + denom + " " + dpVesting);
dpVesting = dpVesting.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : dpVesting;
WLog.w("dpVestingB " + denom + " " + dpVesting);
if (remainVesting.compareTo(delegatedVesting) > 0) {
dpBalance = dpBalance.subtract(remainVesting).add(delegatedVesting);
}
WLog.w("final dpBalance " + denom + " " + dpBalance);
if (dpVesting.compareTo(BigDecimal.ZERO) > 0) {
Coin vestingCoin = new Coin(denom, dpVesting.toPlainString());
baseData.mGrpcVesting.add(vestingCoin);
int replace = -1;
for (int i = 0; i < baseData.mGrpcBalance.size(); i++) {
if (baseData.mGrpcBalance.get(i).denom.equals(denom)) {
replace = i;
}
}
if (replace >= 0) {
baseData.mGrpcBalance.set(replace, new Coin(denom, dpBalance.toPlainString()));
}
}
}
} else if (account.getTypeUrl().contains(Vesting.DelayedVestingAccount.getDescriptor().getFullName())) {
Vesting.DelayedVestingAccount vestingAccount = null;
try {
vestingAccount = Vesting.DelayedVestingAccount.parseFrom(account.getValue());
} catch (InvalidProtocolBufferException e) {
WLog.e("onParseVestingAccount " + e.getMessage());
return;
}
for (Coin coin : sBalace) {
String denom = coin.denom;
BigDecimal dpBalance = BigDecimal.ZERO;
BigDecimal dpVesting = BigDecimal.ZERO;
BigDecimal originalVesting = BigDecimal.ZERO;
BigDecimal remainVesting = BigDecimal.ZERO;
BigDecimal delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
WLog.w("dpBalance " + denom + " " + dpBalance);
for (CoinOuterClass.Coin vesting : vestingAccount.getBaseVestingAccount().getOriginalVestingList()) {
if (vesting.getDenom().equals(denom)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.getAmount()));
}
}
WLog.w("originalVesting " + denom + " " + originalVesting);
long cTime = Calendar.getInstance().getTime().getTime();
long vestingEnd = vestingAccount.getBaseVestingAccount().getEndTime() * 1000;
if (cTime < vestingEnd) {
remainVesting = originalVesting;
}
WLog.w("remainVesting " + denom + " " + remainVesting);
for (CoinOuterClass.Coin vesting : vestingAccount.getBaseVestingAccount().getDelegatedVestingList()) {
if (vesting.getDenom().equals(denom)) {
delegatedVesting = delegatedVesting.add(new BigDecimal(vesting.getAmount()));
}
}
WLog.w("delegatedVesting " + denom + " " + delegatedVesting);
dpVesting = remainVesting.subtract(delegatedVesting);
WLog.w("dpVestingA " + denom + " " + dpVesting);
dpVesting = dpVesting.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : dpVesting;
WLog.w("dpVestingB " + denom + " " + dpVesting);
if (remainVesting.compareTo(delegatedVesting) > 0) {
dpBalance = dpBalance.subtract(remainVesting).add(delegatedVesting);
}
WLog.w("final dpBalance " + denom + " " + dpBalance);
if (dpVesting.compareTo(BigDecimal.ZERO) > 0) {
Coin vestingCoin = new Coin(denom, dpVesting.toPlainString());
baseData.mGrpcVesting.add(vestingCoin);
int replace = -1;
for (int i = 0; i < baseData.mGrpcBalance.size(); i++) {
if (baseData.mGrpcBalance.get(i).denom.equals(denom)) {
replace = i;
}
}
if (replace >= 0) {
baseData.mGrpcBalance.set(replace, new Coin(denom, dpBalance.toPlainString()));
}
}
}
}
}
use of com.google.protobuf2.Any in project cosmostation-android by cosmostation.
the class Signer method getClaimRewardsMsg.
public static ArrayList<Any> getClaimRewardsMsg(QueryOuterClass.QueryAccountResponse auth, ArrayList<String> toValAddresses) {
ArrayList<Any> msgAnys = new ArrayList<>();
for (String valAddr : toValAddresses) {
cosmos.distribution.v1beta1.Tx.MsgWithdrawDelegatorReward msgClaimReward = cosmos.distribution.v1beta1.Tx.MsgWithdrawDelegatorReward.newBuilder().setDelegatorAddress(onParseAddress(auth)).setValidatorAddress(valAddr).build();
Any msgClaimRewardAny = Any.newBuilder().setTypeUrl("/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward").setValue(msgClaimReward.toByteString()).build();
msgAnys.add(msgClaimRewardAny);
}
return msgAnys;
}
Aggregations