for (TransactionInput input : tx.getInputs()) {
JSONObject inputData = new JSONObject();
if (!input.isCoinBase()) {
try {
Script scriptSig = input.getScriptSig();
Address fromAddress = new Address(networkParams, Utils.sha256hash160(scriptSig.getPubKey()));
inputData.put("address", fromAddress);
} catch (ScriptException e) {
// can't parse script, give up
}
}
TransactionOutput source = input.getConnectedOutput();
if (source != null) {
inputData.put("amount", source.getValue());
}
inputs.put(inputData);
}
JSONArray outputs = new JSONArray();
for (TransactionOutput output : tx.getOutputs()) {
JSONObject outputData = new JSONObject();
try {
Script scriptPubKey = output.getScriptPubKey();
if (scriptPubKey.isSentToAddress() || scriptPubKey.isPayToScriptHash()) {
Address toAddress = scriptPubKey.getToAddress(networkParams);
outputData.put("address", toAddress);
if (toAddress.toString().equals(getWalletAddress())) {
outputData.put("type", "own");
} else {
outputData.put("type", "external");
}
} else if (scriptPubKey.isSentToRawPubKey()) {
outputData.put("type", "pubkey");
} else if (scriptPubKey.isSentToMultiSig()) {
outputData.put("type", "multisig");
} else {
outputData.put("type", "unknown");
}
} catch (ScriptException e) {