Skip to content

Commit

Permalink
Add transaction ID, entitlement count and copy
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed Jan 21, 2024
1 parent acb9166 commit 653e2d0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/bearwaves/eos4j/EOSEcom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/bearwaves/eos4j/EOSEcomNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,61 @@ static native EOSEcom.Transaction copyTransactionByIndex(
static native void releaseTransaction(long handle); /*
EOS_Ecom_Transaction_Release(reinterpret_cast<EOS_Ecom_HTransaction>(handle));
*/

static native String transactionGetTransactionId(long transactionHandle); /*
int32_t length = 100;
char buffer[length];
EOS_Ecom_Transaction_GetTransactionId(
reinterpret_cast<EOS_Ecom_HTransaction>(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<EOS_Ecom_HTransaction>(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(&copy_options, 0, sizeof(copy_options));
copy_options.ApiVersion = EOS_ECOM_TRANSACTION_COPYENTITLEMENTBYINDEX_API_LATEST;
copy_options.EntitlementIndex = static_cast<int>(index);
EOS_Ecom_Entitlement* out;
auto copy_result = EOS_Ecom_Transaction_CopyEntitlementByIndex(reinterpret_cast<EOS_Ecom_HTransaction>(transactionHandle), &copy_options, &out);
if (copy_result != EOS_EResult::EOS_Success) {
EOS4J::throwEOSException(env, static_cast<int>(copy_result));
return nullptr;
}
jclass result_cls = env->FindClass("com/bearwaves/eos4j/EOSEcom$Entitlement");
jmethodID result_ctor = env->GetMethodID(result_cls, "<init>", "(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, "<init>", "(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
);
*/
}

0 comments on commit 653e2d0

Please sign in to comment.