Search in sources :

Example 16 with Any

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;
}
Also used : Tx(cosmos.gov.v1beta1.Tx) Any(com.google.protobuf2.Any)

Example 17 with Any

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;
}
Also used : Coin(wannabit.io.cosmostaion.model.type.Coin) Tx(cosmos.gov.v1beta1.Tx) ArrayList(java.util.ArrayList) CoinOuterClass(cosmos.base.v1beta1.CoinOuterClass) Duration(com.google.protobuf.Duration) Any(com.google.protobuf2.Any)

Example 18 with Any

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;
}
Also used : PFX(org.mozilla.jss.pkcs12.PFX) SET(org.mozilla.jss.asn1.SET) Attribute(org.mozilla.jss.pkix.primitive.Attribute) BMPString(org.mozilla.jss.asn1.BMPString) SafeBag(org.mozilla.jss.pkcs12.SafeBag) ANY(org.mozilla.jss.asn1.ANY) FileInputStream(java.io.FileInputStream) AuthenticatedSafes(org.mozilla.jss.pkcs12.AuthenticatedSafes) ASN1Value(org.mozilla.jss.asn1.ASN1Value) BufferedInputStream(java.io.BufferedInputStream) SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) MessageDigest(java.security.MessageDigest) BMPString(org.mozilla.jss.asn1.BMPString) AMPassword(com.sun.identity.security.keystore.AMPassword) Password(org.mozilla.jss.util.Password)

Example 19 with Any

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()));
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SpannableString(android.text.SpannableString) Any(com.google.protobuf2.Any) Vesting(cosmos.vesting.v1beta1.Vesting) BigDecimal(java.math.BigDecimal) Coin(wannabit.io.cosmostaion.model.type.Coin) CoinOuterClass(cosmos.base.v1beta1.CoinOuterClass)

Example 20 with Any

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;
}
Also used : Tx(cosmos.gov.v1beta1.Tx) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Any(com.google.protobuf2.Any)

Aggregations

Any (com.google.protobuf2.Any)17 ANY (org.mozilla.jss.asn1.ANY)16 ArrayList (java.util.ArrayList)13 Tx (cosmos.gov.v1beta1.Tx)11 SET (org.mozilla.jss.asn1.SET)9 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)8 SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)8 OCTET_STRING (org.mozilla.jss.asn1.OCTET_STRING)7 Attribute (org.mozilla.jss.pkix.primitive.Attribute)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ASN1Value (org.mozilla.jss.asn1.ASN1Value)6 BMPString (org.mozilla.jss.asn1.BMPString)6 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)5 ByteString (com.google.protobuf.ByteString)4 CoinOuterClass (cosmos.base.v1beta1.CoinOuterClass)4 OBJECT_IDENTIFIER (org.mozilla.jss.asn1.OBJECT_IDENTIFIER)4 CryptoToken (org.mozilla.jss.crypto.CryptoToken)4 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3