All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wavesplatform.protobuf.transaction.PBAmounts.scala Maven / Gradle / Ivy

The newest version!
package com.wavesplatform.protobuf.transaction

import com.google.protobuf.ByteString
import com.wavesplatform.protobuf._
import com.wavesplatform.transaction.Asset
import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves}

object PBAmounts {
  def toPBAssetId(asset: Asset): ByteString = asset match {
    case Asset.IssuedAsset(id) => id.toByteString
    case Asset.Waves           => ByteString.EMPTY
  }

  def toVanillaAssetId(byteStr: ByteString): Asset = {
    if (byteStr.isEmpty) Waves
    else IssuedAsset(byteStr.toByteStr)
  }

  def fromAssetAndAmount(asset: Asset, amount: Long): Amount =
    Amount(toPBAssetId(asset), amount)

  def toAssetAndAmount(value: Amount): (Asset, Long) =
    (toVanillaAssetId(value.assetId), value.amount)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy