My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
Alexander Codes

10 likes

·

193 reads

9 comments

Eldar Ahmadov
Eldar Ahmadov
Apr 20, 2024

Heard about UTXOs few times, never really bothered to understand what they are, thanks for a clear explanation, Alex. Basically, they're somewhat similar to double entry in bookkeeping.

As usual, got a question regarding the example (can't help it ) :))

How would an account get hold of output Utxos, assuming the account wants to spend it later? _mint_utxo returns an asset_id, but in process_transaction method, those newly minted asset ids are not returned?

2
·
·7 replies
Alexander Codes
Alexander Codes
Author
·Apr 20, 2024

No worries, I enjoy your feedback and questions!

The asset ID is returned from the convert_algo_to_utxo method mainly as a convenience for testing.

You can check which assets an account owns any time off chain using the Algod API.

For any asset other than Algo, an account has to opt in to receive it. The only exception is for assets created by the account. There's no opt-in method in the contract, so it's impossible for anyone to send any other assets to it. So you can be certain that every asset owned by the contract was created by the contract, and is therefore a UTXO :)

This is kind of similar to how Cardano works - it is the job of off chain code (wallets/dapps) to use the indexer to find suitable UTXOs to use for inputs, and to propose the transaction outputs.

The network only validates that the UTXOs can be spent (checking signatures) and validates that the input and output amounts match.

10
·
Eldar Ahmadov
Eldar Ahmadov
Apr 20, 2024

Ok, understood, thank you.

One more (quick) question if I may:

tx_out = tx_outs[i].copy()

Why the .copy()?

Alexander Codes

·
Alexander Codes
Alexander Codes
Author
·Apr 20, 2024

Eldar Ahmadov Good question... I added that because the compiler told me to!

I think it's because ARC-4 dynamic arrays and structs are mutable.

For immutable types like UInt64, String etc. you can assign the value to a new variable and it returns a new value.

Whereas for the mutable types, it would be like creating another reference to the same object, which I don't think the compiler allows.

In Python, if you run:

a = [1, 2, 3]

b = a

b.pop()

print(a, b)

the output is [1, 2] [1, 2]

because b is a reference to the same object as a.

I'm not 100% sure though - hopefully that's covered in more detail in future documentation.

·
Alexander Codes
Alexander Codes
Author
·Apr 20, 2024

Alexander Codes Just to complete the Python example:

a = [1, 2, 3]

b = a.copy()

b.pop()

print(a, b)

[1, 2, 3] [1, 2]

·
Eldar Ahmadov
Eldar Ahmadov
Apr 21, 2024

Ok, understood, although it's a bit strange, since you're not mutating tx_out in this case. Anyway, massive thanks again, and looking forward to the next one! I'm learning a lot from these!

Alexander Codes

·
Alexander Codes
Alexander Codes
Author
·Apr 21, 2024

Eldar Ahmadov Agreed, and it's also a bit weird that you can't iterate over a mutable data structure directly.

I would imagine that might change in future releases.

In any case... I do what the compiler tells me to do :D

·
Eldar Ahmadov
Eldar Ahmadov
Apr 21, 2024

We all do :) Although sometimes I feel like the compiler ignores my comments :)))

Alexander Codes

1
·
Kardo Locksmith
Kardo Locksmith
May 1, 2024

good

1
·