From 653e2d0a1e6990a130bfbec3c29235c53bcb0d90 Mon Sep 17 00:00:00 2001 From: Joel Auterson Date: Sun, 21 Jan 2024 15:31:25 +0000 Subject: [PATCH] Add transaction ID, entitlement count and copy --- README.md | 4 +- .../java/com/bearwaves/eos4j/EOSEcom.java | 20 +++++++ .../com/bearwaves/eos4j/EOSEcomNative.java | 56 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c65dc99..56f3e91 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,9 @@ function. - Entitlements (query/count/copy), entitlement token, redeem - Query ownership, ownership token - Checkout -- Transaction count and copy by ID/index +- Transactions + - Count and copy by ID/index + - Get transaction ID, count and copy entitlements If there's something missing that you need, please do open an issue. PRs are very welcome. diff --git a/src/main/java/com/bearwaves/eos4j/EOSEcom.java b/src/main/java/com/bearwaves/eos4j/EOSEcom.java index 6c8dc47..033ea01 100644 --- a/src/main/java/com/bearwaves/eos4j/EOSEcom.java +++ b/src/main/java/com/bearwaves/eos4j/EOSEcom.java @@ -199,6 +199,26 @@ public static class Transaction extends EOSHandle { public void release() { EOSEcomNative.releaseTransaction(ptr); } + + public String getTransactionId() { + return EOSEcomNative.transactionGetTransactionId(ptr); + } + + public int getEntitlementsCount() { + return EOSEcomNative.transactionGetEntitlementsCount(ptr); + } + + public Entitlement copyEntitlementByIndex(CopyEntitlementByIndexOptions options) throws EOSException { + return EOSEcomNative.transactionCopyEntitlementByIndex(ptr, options); + } + + public static class CopyEntitlementByIndexOptions { + public final int entitlementIndex; + + public CopyEntitlementByIndexOptions(int entitlementIndex) { + this.entitlementIndex = entitlementIndex; + } + } } // Options structs diff --git a/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java b/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java index 055f33e..17cdaf4 100644 --- a/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java +++ b/src/main/java/com/bearwaves/eos4j/EOSEcomNative.java @@ -650,5 +650,61 @@ static native EOSEcom.Transaction copyTransactionByIndex( static native void releaseTransaction(long handle); /* EOS_Ecom_Transaction_Release(reinterpret_cast(handle)); */ + + static native String transactionGetTransactionId(long transactionHandle); /* + int32_t length = 100; + char buffer[length]; + EOS_Ecom_Transaction_GetTransactionId( + reinterpret_cast(transactionHandle), + buffer, + &length + ); + return env->NewStringUTF(buffer); + */ + + static native int transactionGetEntitlementsCount(long transactionHandle); /* + EOS_Ecom_Transaction_GetEntitlementsCountOptions count_options; + memset(&count_options, 0, sizeof(count_options)); + count_options.ApiVersion = EOS_ECOM_TRANSACTION_GETENTITLEMENTSCOUNT_API_LATEST; + + return EOS_Ecom_Transaction_GetEntitlementsCount(reinterpret_cast(transactionHandle), &count_options); + */ + + static native EOSEcom.Entitlement transactionCopyEntitlementByIndex( + long transactionHandle, EOSEcom.Transaction.CopyEntitlementByIndexOptions options + ) throws EOSException; /* + auto index = EOS4J::javaIntFromObjectField(env, options, "entitlementIndex"); + + EOS_Ecom_Transaction_CopyEntitlementByIndexOptions copy_options; + memset(©_options, 0, sizeof(copy_options)); + copy_options.ApiVersion = EOS_ECOM_TRANSACTION_COPYENTITLEMENTBYINDEX_API_LATEST; + copy_options.EntitlementIndex = static_cast(index); + + EOS_Ecom_Entitlement* out; + auto copy_result = EOS_Ecom_Transaction_CopyEntitlementByIndex(reinterpret_cast(transactionHandle), ©_options, &out); + if (copy_result != EOS_EResult::EOS_Success) { + EOS4J::throwEOSException(env, static_cast(copy_result)); + return nullptr; + } + + jclass result_cls = env->FindClass("com/bearwaves/eos4j/EOSEcom$Entitlement"); + jmethodID result_ctor = env->GetMethodID(result_cls, "", "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;IZLjava/util/Date;)V"); + + jclass date_cls = env->FindClass("java/util/Date"); + jmethodID date_ctor = env->GetMethodID(date_cls, "", "(J)V"); + jobject end = out->EndTimestamp == EOS_ECOM_ENTITLEMENT_ENDTIMESTAMP_UNDEFINED ? nullptr : env->NewObject(date_cls, date_ctor, out->EndTimestamp); + + return env->NewObject( + result_cls, + result_ctor, + (long long) out, + env->NewStringUTF(out->EntitlementName), + env->NewStringUTF(out->EntitlementId), + env->NewStringUTF(out->CatalogItemId), + out->ServerIndex, + out->bRedeemed, + end + ); + */ }