Page 1 of 1

beginTransaction & commitTransaction

Posted: Thu Mar 16, 2017 5:32 am
by z535539710
Hi all

I wonder when should I use beginTransaction & commitTransaction functions during javacard applet developing? Any common scenes? :?

your answer is very appreciated :!:

Re: beginTransaction & commitTransaction

Posted: Thu Mar 16, 2017 10:22 pm
by UNKNwYSHSA
For example, you write a wallet applet.
At the end of a transaction (consumption), you write new balance and a transaction log to NVM. Code as following:

Code: Select all

JCSystem.beginTransaction();
// Write new balance;
// Write the transaction log;
// Write other data related to this transaction;
JCSystem.endTransaction()

The write operation is atomically, both the new balance and the transaction log are written, or both not written.

Re: beginTransaction & commitTransaction

Posted: Fri Mar 17, 2017 8:48 am
by tay00000
Imagine a scenario where you decide to write very important data. One example being provisioning a bunch of cryptographic keys to the cards and then you accidentally trip over the card reader and dislodge it from the host computer. Now you have half provisioned keys and you cannot assert their integrity.

The beginTransaction and commitTransaction is to ensure that either all the data are properly committed in an atomic manner or it would simply fail. Think along the line of database commits where the data entry either properly commits or fails gracefully. It is to ensure that in the event something happens, the data would fail gracefully and you won't have half baked data inside the card.

Re: beginTransaction & commitTransaction

Posted: Mon Mar 20, 2017 2:27 am
by z535539710
tay00000 wrote:Imagine a scenario where you decide to write very important data. One example being provisioning a bunch of cryptographic keys to the cards and then you accidentally trip over the card reader and dislodge it from the host computer. Now you have half provisioned keys and you cannot assert their integrity.

The beginTransaction and commitTransaction is to ensure that either all the data are properly committed in an atomic manner or it would simply fail. Think along the line of database commits where the data entry either properly commits or fails gracefully. It is to ensure that in the event something happens, the data would fail gracefully and you won't have half baked data inside the card.


thank you very much, your answer helps a lot