org.spongycastle.util.encoders.DecoderException Java Examples

The following examples show how to use org.spongycastle.util.encoders.DecoderException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignFragment.java    From tron-wallet-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if(result != null) {
        if(result.getContents() != null) {
            try {
                Protocol.Transaction transaction = Protocol.Transaction.parseFrom(Hex.decode(result.getContents()));
                if(getContext() != null) {
                    ConfirmTransactionActivity.start(getContext(), transaction);
                }
            } catch (InvalidProtocolBufferException | DecoderException ignored) { }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example #2
Source File: Utils.java    From wkcwallet-java with Apache License 2.0 5 votes vote down vote up
/**
    * Decodes a hex string to address bytes and checks validity
    *
    * @param hex
    *            - a hex string of the address, e.g.,
    *            6c386a4b26f73c802f34673f7248bb118f97424a
    * @return - decode and validated address byte[]
    */
   public static byte[] addressStringToBytes(String hex) {
final byte[] addr;
try {
    addr = Hex.decode(hex);
} catch (DecoderException addressIsNotValid) {
    return null;
}

if (isValidAddress(addr))
    return addr;
return null;
   }
 
Example #3
Source File: SignedTransactionActivity.java    From tron-wallet-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signed_transaction);

    mSignedTransactionQR_ImageView = findViewById(R.id.SignedTransaction_qr_imageView);
    mConstraintLayout = findViewById(R.id.SignedTransaction_constraintLayout);

    mConstraintLayout.setVisibility(View.INVISIBLE);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        try {
            mTransactionSigned = Protocol.Transaction.parseFrom(extras.getByteArray(TRANSACTION_DATA_EXTRA));
        } catch (InvalidProtocolBufferException | DecoderException ignored) {
        }
    }

    if (mTransactionSigned != null) {
        mSignedTransactionQR_ImageView.setImageBitmap(Utils.strToQR(Hex.toHexString(mTransactionSigned.toByteArray()), 650, 650));
        showQR();
    } else {
        new LovelyStandardDialog(SignedTransactionActivity.this)
                .setTopColorRes(R.color.colorPrimary)
                .setIcon(R.drawable.ic_info_white_24px)
                .setTitle(R.string.invalid_transaction)
                .setMessage(R.string.no_valid_transaction_detected)
                .setPositiveButton(R.string.ok, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                })
                .show();
    }
}
 
Example #4
Source File: Utils.java    From asf-sdk with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Decodes a hex string to address bytes and checks validity
 *
 * @param hex - a hex string of the address, e.g., 6c386a4b26f73c802f34673f7248bb118f97424a
 *
 * @return - decode and validated address byte[]
 */
public static byte[] addressStringToBytes(String hex) {
  byte[] addr;
  try {
    addr = Hex.decode(hex);
  } catch (DecoderException addressIsNotValid) {
    return null;
  }

  if (isValidAddress(addr)) return addr;
  return null;
}
 
Example #5
Source File: Utils.java    From nuls with MIT License 5 votes vote down vote up
/**
 * Decodes a hex string to address bytes and checks validity
 *
 * @param hex - a hex string of the address, e.g., 6c386a4b26f73c802f34673f7248bb118f97424a
 * @return - decode and validated address byte[]
 */
public static byte[] addressStringToBytes(String hex) {
    final byte[] addr;
    try {
        addr = Hex.decode(hex);
    } catch (DecoderException addressIsNotValid) {
        return null;
    }

    if (isValidAddress(addr)) {
        return addr;
    }
    return null;
}
 
Example #6
Source File: Utils.java    From ethereumj with MIT License 5 votes vote down vote up
/**
   * Decodes a hex string to address bytes and checks validity 
   * 
   * @param hex - a hex string of the address, e.g., 6c386a4b26f73c802f34673f7248bb118f97424a
   * @return - decode and validated address byte[]
   */
  public static byte[] addressStringToBytes(String hex) {
  	byte[] addr = null;
try { addr = Hex.decode(hex); }
  	catch(DecoderException addressIsNotValid) { return null; }

if(isValidAddress(addr))
	return addr;
return null;
  }
 
Example #7
Source File: SignTransactionActivity.java    From tron-wallet-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_transaction);

    mUnsignedTransactionQR_ImageView = findViewById(R.id.SignTransaction_qr_imageView);
    mSignedTransaction_Switch = findViewById(R.id.SignTransaction_signed_switch);
    mScanFromColdWallet_Button = findViewById(R.id.SignTransaction_qr_imageButton);

    mColdWalletQR_ConstraintLayout = findViewById(R.id.SignTransaction_cold_wallet_qr_constraintLayout);
    mScanColdWalletQR_ConstraintLayout = findViewById(R.id.SignTransaction_scan_cold_wallet_qr_constraintLayout);


    mScanColdWalletQR_ConstraintLayout.setAlpha(0);

    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        try {
            byte[] transactionData = extras.getByteArray(TRANSACTION_DATA_EXTRA);
            mTransactionUnsigned = Protocol.Transaction.parseFrom(transactionData);

            if(transactionData != null) {
                Bitmap bitmap = Utils.strToQR(Hex.toHexString(transactionData), 800, 800);
                mUnsignedTransactionQR_ImageView.setImageBitmap(bitmap);
            }
        } catch (DecoderException | IOException e) {
            e.printStackTrace();
        }
    }

    mSignedTransaction_Switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mScanColdWalletQR_ConstraintLayout
                    .animate()
                    .setDuration(150)
                    .alpha(isChecked ? 1 : 0)
                    .scaleX(isChecked ? 1 : 0)
                    .scaleY(isChecked ? 1 : 0)
                    .start();
        }
    });

    mScanFromColdWallet_Button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IntentIntegrator integrator = new IntentIntegrator(SignTransactionActivity.this);
            integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
            integrator.setPrompt(getString(R.string.scan_signed_transaction));
            integrator.setCameraId(0);
            integrator.setBeepEnabled(false);
            integrator.setOrientationLocked(true);
            integrator.setCaptureActivity(CaptureActivityPortrait.class);
            integrator.initiateScan();
        }
    });
}