Search code examples
hyperledgerencodehyperledger-composer

How to do URL encoder in Hyperledger composer


I need to do query inside logic.js with special character. I have already done the query logic.

My problem occurs when I put special character as one of the parameter.

When I put 'がが', it cannot find the query. When I put its URL encode, I can find the query result. How do I encode my special word in my logic.js so I can query my word?

This is my code

/**
 * Track the trade of a commodity from one trader to another
 * @param {org.stock.mynetwork.Receive} receive - the receive to be processed
 * @transaction
 */
async function receiveCommodity(receive) {


    let statement = 'SELECT org.stock.mynetwork.Commodity WHERE (owner == _$owner AND dataType == _$dataType)';
    let qry = buildQuery(statement);
    //this works
    let allAssets = await query(qry, { owner: 'resource:org.stock.mynetwork.Trader#'+'%E3%81%8C%E3%81%8C', dataType: receive.dataType });
    //this dont
    let allAssets = await query(qry, { owner: 'resource:org.stock.mynetwork.Trader#'+'がが', dataType: receive.dataType });

}

Solution

  • I was searching at the wrong side of SO post, the solution is easy

    I just need to encodeURI(yourVariable.toString())