Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add implicit BorshSchema derive for store::UnorderedMap #1209

Merged
merged 5 commits into from
Jun 29, 2024

Conversation

dj8yfo
Copy link
Collaborator

@dj8yfo dj8yfo commented Jun 26, 2024

checked against test_unord_map_contract

• Building contract
 │    Compiling test_contract v0.1.0 (/home/user/Documents/code/test_contract)
 │ warning: unused import: `log`
 │  --> src/lib.rs:1:16
 │   |
 │ 1 | use near_sdk::{log, near};|                ^^^
 │   |
 │   = note: `#[warn(unused_imports)]` on by default
 │
 │ warning: use of deprecated struct `near_sdk::store::UnorderedMap`: Suboptimal iteration performance. See performance considerations doc for details.
 │  --> src/lib.rs:5:33
 │   |
 │ 5 |     greetings: near_sdk::store::UnorderedMap<String, String>,
 │   |                                 ^^^^^^^^^^^^
 │   |
 │   = note: `#[warn(deprecated)]` on by default
 │
 │ warning: use of deprecated struct `near_sdk::store::UnorderedMap`: Suboptimal iteration performance. See performance considerations doc for details.
 │   --> src/lib.rs:11:41
 │    |
 │ 11 |             greetings: near_sdk::store::UnorderedMap::new(b"g"),
 │    |                                         ^^^^^^^^^^^^
 │
 │ warning: `test_contract` (lib) generated 3 warnings (run `cargo fix --lib -p test_contract` to apply 1 suggestion)
 │     Finished `release` profile [optimized] target(s) in 0.31s
✓ Contract successfully built! (in CARGO_NEAR_BUILD_ENVIRONMENT=host)

@dj8yfo dj8yfo marked this pull request as ready for review June 26, 2024 20:33
@dj8yfo dj8yfo force-pushed the unordered_map_add_schema branch 2 times, most recently from 1b96271 to e3a54c2 Compare June 27, 2024 11:50
@dj8yfo dj8yfo marked this pull request as draft June 27, 2024 12:07
@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jun 27, 2024

this line wasn't proxying
from {}__NEAR_SCHEMA_PROXY to the BorshSchema::declaration() of type being derived, but replacing with its own implementation instead.

the change of schema of UnorderedMap<NoSchemaStruct, NoSchemaStruct> in added test
due to change in the mentioned line is from

before

{
    "()": Primitive(
        0,
    ),
    "FreeList": Struct {
        fields: NamedFields(
            [
                (
                    "first_free",
                    "Option<FreeListIndex>",
                ),
                (
                    "occupied_count",
                    "u32",
                ),
                (
                    "elements",
                    "Vector < T >",
                ),
            ],
        ),
    },
    "FreeListIndex": Struct {
        fields: UnnamedFields(
            [
                "u32",
            ],
        ),
    },
    "IndexMap": Struct {
        fields: NamedFields(
            [
                (
                    "prefix",
                    "Vec<u8>",
                ),
            ],
        ),
    },
    "LookupMap": Struct {
        fields: NamedFields(
            [
                (
                    "prefix",
                    "Vec<u8>",
                ),
            ],
        ),
    },
    "Option<FreeListIndex>": Enum {
        tag_width: 1,
        variants: [
            (
                0,
                "None",
                "()",
            ),
            (
                1,
                "Some",
                "FreeListIndex",
            ),
        ],
    },
    "UnorderedMap": Struct {
        fields: NamedFields(
            [
                (
                    "keys",
                    "FreeList < T >",
                ),
                (
                    "values",
                    "LookupMap",
                ),
            ],
        ),
    },
    "Vec<u8>": Sequence {
        length_width: 4,
        length_range: 0..=4294967295,
        elements: "u8",
    },
    "Vector": Struct {
        fields: NamedFields(
            [
                (
                    "len",
                    "u32",
                ),
                (
                    "values",
                    "IndexMap",
                ),
            ],
        ),
    },
    "u32": Primitive(
        4,
    ),
    "u8": Primitive(
        1,
    ),
}

to

after

{
    "()": Primitive(
        0,
    ),
    "FreeList": Struct {
        fields: NamedFields(
            [
                (
                    "first_free",
                    "Option<FreeListIndex>",
                ),
                (
                    "occupied_count",
                    "u32",
                ),
                (
                    "elements",
                    "Vector",
                ),
            ],
        ),
    },
    "FreeListIndex": Struct {
        fields: UnnamedFields(
            [
                "u32",
            ],
        ),
    },
    "IndexMap": Struct {
        fields: NamedFields(
            [
                (
                    "prefix",
                    "Vec<u8>",
                ),
            ],
        ),
    },
    "LookupMap": Struct {
        fields: NamedFields(
            [
                (
                    "prefix",
                    "Vec<u8>",
                ),
            ],
        ),
    },
    "Option<FreeListIndex>": Enum {
        tag_width: 1,
        variants: [
            (
                0,
                "None",
                "()",
            ),
            (
                1,
                "Some",
                "FreeListIndex",
            ),
        ],
    },
    "UnorderedMap": Struct {
        fields: NamedFields(
            [
                (
                    "keys",
                    "FreeList",
                ),
                (
                    "values",
                    "LookupMap",
                ),
            ],
        ),
    },
    "Vec<u8>": Sequence {
        length_width: 4,
        length_range: 0..=4294967295,
        elements: "u8",
    },
    "Vector": Struct {
        fields: NamedFields(
            [
                (
                    "len",
                    "u32",
                ),
                (
                    "values",
                    "IndexMap",
                ),
            ],
        ),
    },
    "u32": Primitive(
        4,
    ),
    "u8": Primitive(
        1,
    ),
}

@dj8yfo dj8yfo force-pushed the unordered_map_add_schema branch 2 times, most recently from 3922ae9 to 1ca16a4 Compare June 27, 2024 16:33
@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jun 27, 2024

@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jun 27, 2024

@dj8yfo dj8yfo marked this pull request as ready for review June 27, 2024 17:01
@dj8yfo dj8yfo marked this pull request as draft June 28, 2024 14:17
@dj8yfo dj8yfo marked this pull request as ready for review June 28, 2024 14:33
@frol frol merged commit 96c277b into near:master Jun 29, 2024
19 checks passed
@frol frol mentioned this pull request Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants