Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vcexnet committed Aug 15, 2021
2 parents 8c9edb0 + d15b403 commit 0ffeb01
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
16 changes: 15 additions & 1 deletion app/src/main/java/com/eacpay/presenter/entities/TxItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ public class TxItem {
private boolean isValid;
private int txSize;
public TxMetaData metaData;
private String txComment;
private String txIPFS;

private TxItem() {
}

public TxItem(long timeStamp, int blockHeight, byte[] hash, String txReversed, long sent,
long received, long fee, String to[], String from[],
long balanceAfterTx, int txSize, long[] outAmounts, boolean isValid) {
long balanceAfterTx, int txSize, long[] outAmounts, boolean isValid,
String txComposedComment) {
this.timeStamp = timeStamp;
this.blockHeight = blockHeight;
this.txReversed = txReversed;
Expand All @@ -38,6 +41,9 @@ public TxItem(long timeStamp, int blockHeight, byte[] hash, String txReversed, l
this.outAmounts = outAmounts;
this.isValid = isValid;
this.txSize = txSize;
int pos = txComposedComment.indexOf("\n");
this.txComment = (pos>0) ? txComposedComment.substring(pos+1) : txComposedComment;
this.txIPFS = (pos>0) ? txComposedComment.substring(0, pos) : "";
}

public int getBlockHeight() {
Expand Down Expand Up @@ -96,4 +102,12 @@ public boolean isValid() {
return isValid;
}

public String getTxComment() {
return txComment;
}

public String getIPFS() {
return txIPFS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -47,6 +48,10 @@ public class FragmentTransactionItem extends Fragment {
private TextView mConfirmationText;
private TextView mAvailableSpend;
private EditText mCommentText;
private EditText mMessageText;
private TextView mMessageCaption;
private TextView mMemoCaption;
private TextView mIPFSLink;
private TextView mAmountText;
private TextView mAddressText;
private TextView mDateText;
Expand All @@ -65,7 +70,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mTitle = (TextView) rootView.findViewById(R.id.title);
mDescriptionText = (TextView) rootView.findViewById(R.id.description_text);
mSubHeader = (TextView) rootView.findViewById(R.id.sub_header);
mCommentText = (EditText) rootView.findViewById(R.id.comment_text);
mCommentText = (EditText) rootView.findViewById(R.id.memo_text);
mMessageText = (EditText) rootView.findViewById(R.id.comment_text);
mIPFSLink = (TextView) rootView.findViewById(R.id.ipfs_link);
mMessageCaption = (TextView) rootView.findViewById(R.id.comment_caption);
mMemoCaption = (TextView) rootView.findViewById(R.id.memo_caption);
mAmountText = (TextView) rootView.findViewById(R.id.amount_text);
mAddressText = (TextView) rootView.findViewById(R.id.address_text);
mDateText = (TextView) rootView.findViewById(R.id.date_text);
Expand Down Expand Up @@ -131,6 +140,8 @@ private void fillTexts() {
String startingBalance = BRCurrency.getFormattedCurrencyString(getActivity(), iso, BRExchange.getAmountFromSatoshis(getActivity(), iso, new BigDecimal(sent ? item.getBalanceAfterTx() + txAmount.longValue() : item.getBalanceAfterTx() - txAmount.longValue())));
String endingBalance = BRCurrency.getFormattedCurrencyString(getActivity(), iso, BRExchange.getAmountFromSatoshis(getActivity(), iso, new BigDecimal(item.getBalanceAfterTx())));
String commentString = item.metaData == null || item.metaData.comment == null ? "" : item.metaData.comment;
String messageString = item.getTxComment();
String ipfsString = item.getIPFS();
String sb = String.format(getString(R.string.Transaction_starting), startingBalance);
String eb = String.format(getString(R.string.Transaction_ending), endingBalance);
String amountString = String.format("%s %s\n\n%s\n%s", amount, item.getFee() == -1 ? "" : String.format(getString(R.string.Transaction_fee), fee), sb, eb);
Expand All @@ -153,6 +164,20 @@ public void onClick(View view) {
}
});

mIPFSLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Activity app = getActivity();
if (app != null)
app.getFragmentManager().popBackStack();
String txUrl = "https://dweb.link/ipfs/" + item.getIPFS();
Timber.d("txUrl = %s", txUrl);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(txUrl));
startActivity(browserIntent);
app.overridePendingTransition(R.anim.enter_from_bottom, R.anim.empty_300);
}
});

int level = getLevel(item);

boolean availableForSpend = false;
Expand Down Expand Up @@ -205,7 +230,9 @@ public void onClick(View view) {
mDescriptionText.setText(TextUtils.concat(descriptionString));
mSubHeader.setText(toFrom);
mCommentText.setText(commentString);

mMessageText.setText(messageString);
boolean hasTxIPFS = ipfsString.length()>0;
mIPFSLink.setVisibility(hasTxIPFS?View.VISIBLE:View.INVISIBLE);
mAmountText.setText(amountString);
mAddressText.setText(addr);
}
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/jni/eacpay-core/BRTransaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ BRTransaction *BRTransactionCopy(const BRTransaction *tx)
BRTransactionAddOutput(cpy, tx->outputs[i].amount, tx->outputs[i].script, tx->outputs[i].scriptLen);
}

cpy->comment = NULL;
cpy->commentLength = 0;
cpy->version = tx->version;
if ( (tx->version == TX_VERSION_MSG) && (tx->commentLength > 0) && (tx->comment != NULL) ) {
cpy->comment = malloc(1 + tx->commentLength);
if (cpy->comment != NULL) {
memcpy(cpy->comment, tx->comment, tx->commentLength);
cpy->commentLength = tx->commentLength;
cpy->comment[tx->commentLength] = 0;
}
}

return cpy;
}

Expand Down Expand Up @@ -446,9 +458,10 @@ BRTransaction *BRTransactionParse(const uint8_t *buf, size_t bufLen)
tx->commentLength = (size_t)BRVarInt(&buf[off], (off <= bufLen ? bufLen - off : 0), &len);
off += len;
if ((tx->commentLength > 0) && ((off + tx->commentLength) <= bufLen)) {
tx->comment = malloc(tx->commentLength);
tx->comment = malloc(1 + tx->commentLength);
memcpy(tx->comment, &buf[off], tx->commentLength);
off += tx->commentLength;
tx->comment[tx->commentLength] = 0;
} else {
tx->comment = NULL;
tx->commentLength = 0;
Expand Down Expand Up @@ -681,10 +694,11 @@ void BRTransactionSetMessage(BRTransaction * tx, char * comment, size_t comLen)
tx->commentLength = 0;
tx->version = TX_VERSION;
if ( (comLen > 0) && (comment != NULL) ) {
tx->comment = malloc(comLen);
tx->comment = malloc(comLen + 1);
if (tx->comment != NULL) {
memcpy(tx->comment, comment, comLen);
tx->commentLength = comLen;
tx->comment[tx->commentLength] = 0;
tx->version = TX_VERSION_MSG;
}
}
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/jni/transition/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_eacpay_wallet_BRWalletManager_getTransac
jobjectArray txObjects = (*env)->NewObjectArray(env, (jsize) txCount, txClass, 0);
jobjectArray globalTxs = (*env)->NewGlobalRef(env, txObjects);
jmethodID txObjMid = (*env)->GetMethodID(env, txClass, "<init>",
"(JI[BLjava/lang/String;JJJ[Ljava/lang/String;[Ljava/lang/String;JI[JZ)V");
"(JI[BLjava/lang/String;JJJ[Ljava/lang/String;[Ljava/lang/String;JI[JZLjava/lang/String;)V");
jclass stringClass = (*env)->FindClass(env, "java/lang/String");

for (int i = 0; i < txCount; i++) {
Expand All @@ -374,6 +374,11 @@ JNIEXPORT jobjectArray JNICALL Java_com_eacpay_wallet_BRWalletManager_getTransac
jlong JtimeStamp = tempTx->timestamp;
jint JblockHeight = tempTx->blockHeight;
jint JtxSize = (jint) BRTransactionSize(tempTx);

jstring txComment = tempTx->commentLength ?
(*env)->NewStringUTF(env, tempTx->comment) :
(*env)->NewStringUTF(env, "");

UInt256 txid = tempTx->txHash;
jbyteArray JtxHash = (*env)->NewByteArray(env, sizeof(txid));
(*env)->SetByteArrayRegion(env, JtxHash, 0, (jsize) sizeof(txid), (jbyte *) txid.u8);
Expand All @@ -382,7 +387,6 @@ JNIEXPORT jobjectArray JNICALL Java_com_eacpay_wallet_BRWalletManager_getTransac

jstring txReversed = (*env)->NewStringUTF(env, u256hex(reversedHash));


jlong Jsent = (jlong) BRWalletAmountSentByTx(_wallet, tempTx);
jlong Jreceived = (jlong) BRWalletAmountReceivedFromTx(_wallet, tempTx);
jlong Jfee = (jlong) BRWalletFeeForTx(_wallet, tempTx);
Expand Down Expand Up @@ -437,7 +441,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_eacpay_wallet_BRWalletManager_getTransac
JtxHash, txReversed, Jsent,
Jreceived, Jfee, JtoAddresses, JfromAddresses,
JbalanceAfterTx, JtxSize,
JoutAmounts, isValid);
JoutAmounts, isValid, txComment);

(*env)->SetObjectArrayElement(env, globalTxs, (jsize) (txCount - 1 - i), txObject);
(*env)->DeleteLocalRef(env, txObject);
Expand All @@ -446,6 +450,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_eacpay_wallet_BRWalletManager_getTransac
(*env)->DeleteLocalRef(env, JoutAmounts);
(*env)->DeleteLocalRef(env, JtxHash);
(*env)->DeleteLocalRef(env, txReversed);
(*env)->DeleteLocalRef(env, txComment);

}

Expand Down

0 comments on commit 0ffeb01

Please sign in to comment.