aptos-labs / developer-docs

Source for the Aptos developer docs
https://aptos.dev
Apache License 2.0
889 stars 98 forks source link

authorized_borrow_refs unbound variable during Aptos compilation #681

Closed AuroraLantean closed 1 month ago

AuroraLantean commented 1 month ago

Url

https://aptos.dev/en/build/guides/first-fungible-asset#step-433-managing-a-coin

Describe the content issue

authorized_borrow_refs unbound variable during Aptos compilation How to import authorized_borrow_refs ?

Section

move-and-smart-contracts

github-actions[bot] commented 1 month ago

@aptos-labs/move-eng

AuroraLantean commented 1 month ago

Solved by adding this inline function:

    /// Borrow the immutable reference of the refs of `metadata`.
    /// This validates that the signer is the metadata object's owner.
    inline fun authorized_borrow_refs(
        owner: &signer,
        asset: Object<Metadata>,
    ): &ManagedFungibleAsset acquires ManagedFungibleAsset {
        assert!(object::is_owner(asset, signer::address_of(owner)), error::permission_denied(ENOT_OWNER));
        borrow_global<ManagedFungibleAsset>(object::object_address(&asset))
    }

Reference: https://github.com/aptos-labs/aptos-core/blob/50104947083b7c6b3eee9f764f411d3031334a9a/testsuite/module-publish/src/packages/framework_usecases/sources/fungible_asset_example.move#L78