Skip to content

tokenBalance Internal Action

Nilson Lazarin edited this page Sep 12, 2024 · 2 revisions
Internal Actions Wiki

.velluscinum.tokenBalance

Check units of a specific token into a wallet and return a belief like: q(C,V);

DESCRIPTION

.velluscinum.tokenBalance(S,P,Q,C,q);
Parameters Description
q It's a belief that represents the balance of C in the agent's wallet.
C It's a literal that represents a divisible asset.
P It's a literal that represents the agent's private key.
Q It's a literal that represents the agent's public key.
S It's a literal that represents the address of a DLT node.
V It's a integer that represents the number of parts of a C.

EXAMPLE

1 - Alice Agent

/* Initial beliefs and rules */
myWallet("7neiPonWcQEXBoHooxMhTVvHQFAJGDdZYF1HuPTgH5ia","C9q3KZzdBXaTyCpLUyizFXZQaPcZX3RjH8wLavRA91Lk").

/* Plans */
+!showBalance(S,C):myWallet(P,Q) <-
	.abolish(balance(_,_));
	.velluscinum.tokenBalance(S,P,Q,C,balance);
	.wait(balance(C,Units));
	.print("Exists ",Units," of ",C," in my wallet!");
	.random(W); .wait(5000*W);
	!showBalance(S,C);
.

2 - Bob Agent

/* Initial beliefs and rules */
bigChainDB("http://testchain.chon.group:9984/").
alicePublicKey("C9q3KZzdBXaTyCpLUyizFXZQaPcZX3RjH8wLavRA91Lk").

/* Initial goals */
!start.

/* Plans */
+!start <- 
	?bigChainDB(S);
	.velluscinum.buildWallet(myWallet);
	.wait(myWallet(P,Q));
	.velluscinum.deployToken(S,P,Q,"name:MyCoin;type:criptocurrency",100000,myCoin);
	.wait(myCoin(TokenID));
	.broadcast(achieve,showBalance(S,TokenID));
	?alicePublicKey(AliceWallet);
	!transferToken(S,P,Q,TokenID,AliceWallet,10);
.

+!transferToken(S,P,Q,C,R,V) <-
	.random(W); .wait(5000*W);
	.velluscinum.transferToken(S,P,Q,C,R,V);
	.print("Transfered ",V," Units...");
	!transferToken(S,P,Q,C,R,V*10);
.

-!transferToken(S,P,Q,C,R,V) <-
	.print("I don't have sufficient tokens...");
	.wait(10000); .stopMAS;
.