Home > database >  How can we convert ErgoValue of a Coll[Byte] to StandardCharsets.UTF_8?
How can we convert ErgoValue of a Coll[Byte] to StandardCharsets.UTF_8?

Time:07-11

When inserting a string into registers in Ergo, I have this code

val byteColl = Javahelpers.SigmaDsl.Colls.fromArray(String.getBytes("utf-8"))
ErgoValue.Of(byteColl, ErgoType.byteType())

However, when I'm trying to compare the CollByte within the ErgoBox, with say, a token Id. I'm not getting the right String.

For example, for SigUSD, The id is: 03faf2cb329f2e90d6d23b58d91bbb6c046aa143261cc21f52fbe2824bfcbf04 However I'd get: [B@7a1b8a46

I'm doing println(inputBox.getRegisters.get(0).getValue.asInstanceOf[Coll[Byte]].toArray) to get the value, however I believe that value should be the same when evaluating ErgoScript?

How can I compare tokenId vs a stored string when evaluating within ErgoScript?

CodePudding user response:

First of all, you don't need to convert to Coll[Byte] before using ErgoValue.of() in appkit. You can just insert a String with

ErgoValue.of(text.getBytes(StandardCharsets.UTF_8))

In ErgoScript, the equation will work differently than in Java. Comparing two Coll[Byte] values of same content will return true, while in Java, it returns false (because Java uses identity as comparison, Scala/ErgoScript equality).

  • Related