Skip to content

Commit

Permalink
Merge #3424
Browse files Browse the repository at this point in the history
3424: Light mode: Tx includes non-native assets r=Unisay a=Unisay

Originally, light-mode implementation supported only ADA coins, ignoring all non-ADA assets. 

This PR adds a support for the non-ADA assets.

### Issue Number

ADP-1777


Co-authored-by: Yuriy Lazaryev <yuriy.lazaryev@iohk.io>
Co-authored-by: Yura Lazarev <Unisay@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 9, 2022
2 parents 1f8288d + f816524 commit 34c1da5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/shelley/src/Cardano/Wallet/Shelley/Network/Blockfrost.hs
Expand Up @@ -129,6 +129,10 @@ import Cardano.Wallet.Primitive.Types.RewardAccount
( RewardAccount )
import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle (..) )
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId (..) )
import Cardano.Wallet.Primitive.Types.TokenQuantity
( TokenQuantity (..) )
import Cardano.Wallet.Primitive.Types.Tx
( Tx (..), TxIn (..), TxOut (..), TxScriptValidity (..), TxSize (..) )
import Cardano.Wallet.Shelley.Network.Blockfrost.Conversion
Expand Down Expand Up @@ -206,7 +210,7 @@ import Data.Set
import Data.Text
( Text )
import Data.Text.Class
( ToText (..) )
( ToText (..), fromText )
import Data.These
( These (That, These, This) )
import Data.Traversable
Expand Down Expand Up @@ -240,6 +244,7 @@ import qualified Cardano.Ledger.Coin as Ledger
import qualified Cardano.Slotting.Time as ST
import qualified Cardano.Wallet.Network.Light as LN
import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
import qualified Cardano.Wallet.Primitive.Types.TokenMap as TokenMap
import qualified Cardano.Wallet.Shelley.Network.Blockfrost.Fixture as Fixture
import qualified Cardano.Wallet.Shelley.Network.Blockfrost.Layer as Layer
import qualified Data.Aeson as Aeson
Expand All @@ -250,6 +255,7 @@ import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Vector as V
import qualified Money
import qualified Ouroboros.Consensus.HardFork.History.Qry as HF
import qualified Ouroboros.Consensus.Util.Counting as UC

Expand Down Expand Up @@ -743,7 +749,22 @@ assembleTransaction
] of
[l] -> fromBfLovelaces l
_ -> throwError $ InvalidUtxoOutputAmount out
pure $ TokenBundle coin mempty -- TODO: Handle native assets
let bfAssets = [ ( Money.someDiscreteCurrency sd
, Money.someDiscreteAmount sd
)
| BF.AssetAmount sd <- _utxoOutputAmount
]
tokens <- for bfAssets \(textValue, a) -> do
-- textValue is hex-encoded,
-- the first 28 bytes are the policy script hash
let (policy, name) = T.splitAt (2*28) textValue
policyId <-
first (InvalidTokenPolicyId policy) (fromText policy)
assetName <-
first (InvalidTokenName name) (fromText name)
assetQuantity <- TokenQuantity <$> (a <?#> "TokenQuantity")
pure (AssetId policyId assetName, assetQuantity)
pure $ TokenBundle coin (TokenMap.fromFlatList tokens)
pure TxOut{..}
withdrawals <-
Map.fromList
Expand Down
Expand Up @@ -47,6 +47,8 @@ data BlockfrostError
| InvalidAddress Text TextDecodingError
| InvalidStakeAddress Text TextDecodingError
| InvalidPoolId Text TextDecodingError
| InvalidTokenPolicyId Text TextDecodingError
| InvalidTokenName Text TextDecodingError
| PoolStakePercentageError Coin Coin
| InvalidDecentralizationLevelPercentage Double
| InvalidPercentage Double MkPercentageError
Expand Down

0 comments on commit 34c1da5

Please sign in to comment.