0

I was looking at fungible_token table inside my PostgreSQL database, and I noticed that all of my records have the same value for the holder field, and that value is the X500 name of my Wallet node; even though all my tokens are issued to accounts on that node (i.e. Wallet node is the host for all of my accounts).

Please note that I'm able to query account balances correctly inside my flows (I understand that it relies on querying the vault_states table and not fungible_token).

  1. Is it by design that the fungible_token table is showing the host of the accounts as the holder of the token?
  2. If so, what would be the proper SQL query to find the balance of a certain account?

Just to be more clear, I'm looking for a SQL that I can write inside pgAdmin - not inside Corda flows.

2 Answers 2

1

I implemented my requirement in 2 ways:

Also, Sneha Damle from R3 provided the SQL query to find an account's balance in her article (Database View paragraph).

Sign up to request clarification or add additional context in comments.

Comments

0

From our recent account library samples, you choose to issue the tokens to the Account directly. https://github.com/corda/samples-kotlin/blob/master/Accounts/worldcupticketbooking/workflows/src/main/kotlin/com/t20worldcup/flows/IssueCashFlow.kt#L42

That said, when you do a query, you just need to specifies the externalID to the AccountID.

For example:

class QuerybyAccount(private val whoAmI:String) : FlowLogic<String>() { override val progressTracker = ProgressTracker() @Suspendable override fun call():String { val myAccount = accountService.accountInfo(whoAmI).single().state.data val criteria = QueryCriteria.VaultQueryCriteria(externalIds = listOf(myAccount.identifier.id)) //Ticket val ticketList = serviceHub.vaultService.queryBy<NonFungibleToken>(criteria = criteria).states val myTicketIDs = ticketList.map { it.state.data.tokenType.tokenIdentifier } val tkList = myTicketIDs.map { val uuid = UUID.fromString(it) val queryCriteria = QueryCriteria.LinearStateQueryCriteria(uuid = listOf(uuid),status = Vault.StateStatus.UNCONSUMED) val stateAndRef = serviceHub.vaultService.queryBy<T20CricketTicketState>(queryCriteria).states[0] val description = stateAndRef.state.data.ticketTeam description } //Assets val asset = serviceHub.vaultService.queryBy(FungibleToken::class.java, criteria).states val myMoney = asset.map { it.state.data.amount.quantity.toString() + " " + it.state.data.tokenType.tokenIdentifier} return "\nI have ticket(s) for $tkList" + "\nI have money of $myMoney" }} 

Full code at: https://github.com/corda/samples-kotlin/tree/master/Accounts/worldcupticketbooking

1 Comment

Peter, please read the last sentence in my question :-) Anyway, I found the answer myself.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.