Initial agreement

As defined in our LC design, the first step in the agreement between buyer and seller is where the buyer agrees to purchase the goods from the seller. Therefore, we define an InitialApplication transaction in our model for all attending participants, including the buyer, seller, and banks. In this step, we define a transaction, which creates a letter of credit with an ID, letterId, and then define the related participants along an event firing a notification regarding the LC creation:

transaction InitialApplication {
o String letterId
--> User buyer
--> User seller
--> Bank issuingBank
--> Bank confirmingBank
o Rule[] rules
o ProductDetails productDetails
}
event InitialApplicationEvent {
--> LetterOfCredit lc
}

The following function represents the process behind the InitialApplication transaction as follows:

#related the transaction processor function
/**
* Create the LC asset
* @param {org.example.lc.InitialApplication} initalAppliation - the InitialApplication transaction
* @transaction
*/
async function initialApplication(application) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.lc';

const letter = factory.newResource(namespace, 'LetterOfCredit', application.letterId);
letter.buyer = factory.newRelationship(namespace, 'User', application.buyer.getIdentifier());
letter.seller =
factory.newRelationship(namespace, 'User',application.seller.getIdentifier());
letter.issuingBank =
factory.newRelationship(namespace,'Bank', application.buyer.bank.getIdentifier());
letter.confirmingBank =
factory.newRelationship(namespace,'Bank',application.seller.bank.getIdentifier());
letter.rules = application.rules;
letter.productDetails = application.productDetails;
letter.evidence = [];
letter.status = 'CONTRACT';
letter.step=0;
//save the application
const assetRegistry = await getAssetRegistry(letter.getFullyQualifiedType());
await assetRegistry.add(letter);
// emit event
const applicationEvent = factory.newEvent(namespace, 'InitialApplicationEvent');
applicationEvent.lc = letter;
emit(applicationEvent);
}

When this function is called, it instantiates a new resource representing our new LC, and then defines the relationship between the LC and the participants using the newRelationship method. Afterward, it sets the letter status to CONTRACT, and LC step to 0 (letter.step=0).

We use the getAssetRegistry method to find the current LC (modeled as an asset in the CTO) in the blockchain using the getfullyQualifiedType method, which returns the fully qualified type name of the indicated instance. Then, we use the add function to add the LC asset to the blockchain.

At the end, we create an event object for the new asset using newEvent with the event namespace, type (InitialApplicationEvent), and then publish the event using the emit function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset