Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/scala/vsys/account/ContractAccount.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package vsys.account

import com.google.common.primitives.Ints
import scorex.crypto.encode.Base58
import vsys.blockchain.state.ByteStr
import vsys.blockchain.transaction.ValidationError
import vsys.blockchain.transaction.ValidationError.{InvalidContractAddress, InvalidAddress}
import vsys.blockchain.transaction.ValidationError.{InvalidAddress, InvalidContractAddress}
import vsys.utils.crypto.hash.SecureCryptographicHash._
import vsys.utils.{base58Length, ScorexLogging}
import vsys.utils.{ScorexLogging, base58Length}

import scala.util.Success

Expand Down Expand Up @@ -112,4 +113,10 @@ object ContractAccount extends ScorexLogging {
ByteStr(bytes)
}

def tokenIndexFromBytes(tokenIdBytes: Array[Byte]): Int = {
val tokenIndexBytes = tokenIdBytes.dropRight(ChecksumLength).takeRight(TokenIndexLength)
val tokenIndex = Ints.fromByteArray(tokenIndexBytes)
tokenIndex
}

}
5 changes: 3 additions & 2 deletions src/main/scala/vsys/api/http/contract/ContractApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.netty.channel.group.ChannelGroup
import io.swagger.annotations._
import play.api.libs.json.{Format, JsArray, JsNumber, JsObject, Json}
import vsys.account.{Account, ContractAccount}
import vsys.account.ContractAccount.{contractIdFromBytes, tokenIdFromBytes}
import vsys.account.ContractAccount.{contractIdFromBytes, tokenIdFromBytes, tokenIndexFromBytes}
import vsys.api.http._
import vsys.blockchain.state.ByteStr
import vsys.blockchain.state.reader.StateReader
Expand Down Expand Up @@ -182,7 +182,8 @@ case class ContractApiRoute (settings: RestAPISettings, wallet: Wallet, utx: Utx
"max" -> x.json.value("data"),
"total" -> state.tokenAccountBalance(totalKey),
"unity" -> state.tokenInfo(unityKey).get.json.value("data"),
"description" -> state.tokenInfo(descKey).get.json.value("data")
"description" -> state.tokenInfo(descKey).get.json.value("data"),
"tokenIndex" -> tokenIndexFromBytes(id.arr)
))
case _ => complete(TokenNotExists)
}
Expand Down