Skip to content

Commit

Permalink
[move-stdlib] use general-purpose GUID's for event handle ID's
Browse files Browse the repository at this point in the history
- Move general-purpose GUID module from the experimental code to the stdlib
- Add unit tests for GUID
- Use a GUID as the unique ID for an event handle instead of an event-specific id.
- Eliminate all references to `Event::publish_generator`, which is no longer needed.
`GUID::create` lazily publishes a `Generator` under the signer's address if it needs to.

The event/GUID correspondence has some potentially useful applications for objects with
globally unique ID's. For example: say you have NFT's and want to support an efficient API
for looking up an NFT by its ID. You can allow each NFT to carry an event stream whose GUID
is used as the unique ID for the NFT. Transfers of the NFT emit events to this stream. This
lets you query the event stream to find both the current account that holds the NFT (it's
the last event emitted to the stream) and the ownership history of the NFT (each event in
the stream represents a transfer).

Closes: aptos-labs#9395
  • Loading branch information
sblackshear authored and bors-libra committed Oct 20, 2021
1 parent 8b68295 commit ddc08b8
Show file tree
Hide file tree
Showing 63 changed files with 1,614 additions and 546 deletions.
18 changes: 0 additions & 18 deletions api/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,6 @@ mod tests {
}
}),
);

let res = find_value(&resp, |v| v["type"]["name"] == "EventHandleGenerator");
assert_json(
res,
json!({
"type": {
"type": "struct",
"address": "0x1",
"module": "Event",
"name": "EventHandleGenerator",
"generic_type_params": []
},
"value": {
"counter": "5",
"addr": "0xdd"
}
}),
);
}

#[tokio::test]
Expand Down
103 changes: 72 additions & 31 deletions json-rpc/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,37 +1752,78 @@ impl PublicUsageTest for GetResourcesTest {
assert_eq!(
currency_info,
&json!({
"total_value": 0,
"preburn_value": 0,
"to_xdx_exchange_rate": {
"value": 4294967296_u64
},
"is_synthetic": true,
"scaling_factor": 1000000,
"fractional_part": 1000,
"currency_code": "XDX",
"can_mint": false,
"mint_events": {
"counter": 0,
"guid": "0a000000000000000000000000000000000000000a550c18"
},
"burn_events": {
"counter": 0,
"guid": "0b000000000000000000000000000000000000000a550c18"
},
"preburn_events": {
"counter": 0,
"guid": "0c000000000000000000000000000000000000000a550c18"
},
"cancel_burn_events": {
"counter": 0,
"guid": "0d000000000000000000000000000000000000000a550c18"
},
"exchange_rate_update_events": {
"counter": 0,
"guid": "0e000000000000000000000000000000000000000a550c18"
}
})
"total_value": 0,
"preburn_value": 0,
"to_xdx_exchange_rate": {
"value": 4294967296_u64
},
"is_synthetic": true,
"scaling_factor": 1000000,
"fractional_part": 1000,
"currency_code": "XDX",
"can_mint": false,
"mint_events": {
"counter": 0,
"guid": {
"len_bytes": 24,
"guid": {
"id": {
"creation_num": 10,
"addr": "a550c18",
}
}
}
},
"burn_events": {
"counter": 0,
"guid": {
"len_bytes": 24,
"guid": {
"id": {
"creation_num": 11,
"addr": "a550c18",
}
}
}
},
"preburn_events": {
"counter": 0,
"guid": {
"len_bytes": 24,
"guid": {
"id": {
"creation_num": 12,
"addr": "a550c18",
}
}
}
},
"cancel_burn_events": {
"counter": 0,
"guid": {
"len_bytes": 24,
"guid": {
"id": {
"creation_num": 13,
"addr": "a550c18",
}
}
}
},
"exchange_rate_update_events": {
"counter": 0,
"guid": {
"len_bytes": 24,
"guid": {
"id": {
"creation_num": 14,
"addr": "a550c18",
}
}
}

}
})
);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,6 @@ AccountOperationsCapability, WriteSetManager, and finally makes the account.
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_diem_root">CoreAddresses::assert_diem_root</a>(&dr_account);
<a href="Roles.md#0x1_Roles_grant_diem_root_role">Roles::grant_diem_root_role</a>(&dr_account);
<a href="SlidingNonce.md#0x1_SlidingNonce_publish">SlidingNonce::publish</a>(&dr_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&dr_account);

<b>assert</b>(
!<b>exists</b>&lt;<a href="DiemAccount.md#0x1_DiemAccount_AccountOperationsCapability">AccountOperationsCapability</a>&gt;(@DiemRoot),
Expand Down Expand Up @@ -2855,7 +2854,6 @@ event handle generator, then makes the account.
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
<a href="Roles.md#0x1_Roles_grant_treasury_compliance_role">Roles::grant_treasury_compliance_role</a>(&new_account, dr_account);
<a href="SlidingNonce.md#0x1_SlidingNonce_publish">SlidingNonce::publish</a>(&new_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="VASPDomain.md#0x1_VASPDomain_publish_vasp_domain_manager">VASPDomain::publish_vasp_domain_manager</a>(&new_account);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix)
}
Expand Down Expand Up @@ -2971,7 +2969,6 @@ Creates Preburn resource under account 'new_account_address'
<a href="DiemTimestamp.md#0x1_DiemTimestamp_assert_operating">DiemTimestamp::assert_operating</a>();
<a href="Roles.md#0x1_Roles_assert_treasury_compliance">Roles::assert_treasury_compliance</a>(creator_account);
<b>let</b> new_dd_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_dd_account);
<a href="Roles.md#0x1_Roles_new_designated_dealer_role">Roles::new_designated_dealer_role</a>(creator_account, &new_dd_account);
<a href="DesignatedDealer.md#0x1_DesignatedDealer_publish_designated_dealer_credential">DesignatedDealer::publish_designated_dealer_credential</a>&lt;CoinType&gt;(&new_dd_account, creator_account, add_all_currencies);
<a href="DualAttestation.md#0x1_DualAttestation_publish_credential">DualAttestation::publish_credential</a>(&new_dd_account, creator_account, human_name);
Expand Down Expand Up @@ -3065,7 +3062,6 @@ all available currencies in the system will also be added.
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
<a href="Roles.md#0x1_Roles_new_parent_vasp_role">Roles::new_parent_vasp_role</a>(creator_account, &new_account);
<a href="VASP.md#0x1_VASP_publish_parent_vasp_credential">VASP::publish_parent_vasp_credential</a>(&new_account, creator_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="DualAttestation.md#0x1_DualAttestation_publish_credential">DualAttestation::publish_credential</a>(&new_account, creator_account, human_name);
<a href="VASPDomain.md#0x1_VASPDomain_publish_vasp_domains">VASPDomain::publish_vasp_domains</a>(&new_account);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix);
Expand Down Expand Up @@ -3166,7 +3162,6 @@ also be added. This account will be a child of <code>creator</code>, which must
parent,
&new_account,
);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix);
<a href="DiemAccount.md#0x1_DiemAccount_add_currencies_for_account">add_currencies_for_account</a>&lt;Token&gt;(&new_account, add_all_currencies);
}
Expand Down Expand Up @@ -4763,7 +4758,6 @@ Create a Validator account
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
// The dr_account account is verified <b>to</b> have the diem root role in `<a href="Roles.md#0x1_Roles_new_validator_role">Roles::new_validator_role</a>`
<a href="Roles.md#0x1_Roles_new_validator_role">Roles::new_validator_role</a>(dr_account, &new_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="ValidatorConfig.md#0x1_ValidatorConfig_publish">ValidatorConfig::publish</a>(&new_account, dr_account, human_name);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix)
}
Expand Down Expand Up @@ -4844,7 +4838,6 @@ Create a Validator Operator account
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
// The dr_account is verified <b>to</b> have the diem root role in `<a href="Roles.md#0x1_Roles_new_validator_operator_role">Roles::new_validator_operator_role</a>`
<a href="Roles.md#0x1_Roles_new_validator_operator_role">Roles::new_validator_operator_role</a>(dr_account, &new_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="ValidatorOperatorConfig.md#0x1_ValidatorOperatorConfig_publish">ValidatorOperatorConfig::publish</a>(&new_account, dr_account, human_name);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ The Move modules in the Diem Framework can be bucketed in to a couple categories
- [`0x1::Errors`](../../../../../../../move-stdlib/docs/Errors.md#0x1_Errors)
- [`0x1::Event`](../../../../../../../move-stdlib/docs/Event.md#0x1_Event)
- [`0x1::FixedPoint32`](../../../../../../../move-stdlib/docs/FixedPoint32.md#0x1_FixedPoint32)
- [`0x1::GUID`](../../../../../../../move-stdlib/docs/GUID.md#0x1_GUID)
- [`0x1::Genesis`](Genesis.md#0x1_Genesis)
- [`0x1::Hash`](../../../../../../../move-stdlib/docs/Hash.md#0x1_Hash)
- [`0x1::NetworkIdentity`](NetworkIdentity.md#0x1_NetworkIdentity)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 0 additions & 7 deletions language/diem-framework/core/doc/DiemAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,6 @@ AccountOperationsCapability, WriteSetManager, and finally makes the account.
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_diem_root">CoreAddresses::assert_diem_root</a>(&dr_account);
<a href="Roles.md#0x1_Roles_grant_diem_root_role">Roles::grant_diem_root_role</a>(&dr_account);
<a href="SlidingNonce.md#0x1_SlidingNonce_publish">SlidingNonce::publish</a>(&dr_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&dr_account);

<b>assert</b>(
!<b>exists</b>&lt;<a href="DiemAccount.md#0x1_DiemAccount_AccountOperationsCapability">AccountOperationsCapability</a>&gt;(@DiemRoot),
Expand Down Expand Up @@ -2855,7 +2854,6 @@ event handle generator, then makes the account.
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
<a href="Roles.md#0x1_Roles_grant_treasury_compliance_role">Roles::grant_treasury_compliance_role</a>(&new_account, dr_account);
<a href="SlidingNonce.md#0x1_SlidingNonce_publish">SlidingNonce::publish</a>(&new_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="VASPDomain.md#0x1_VASPDomain_publish_vasp_domain_manager">VASPDomain::publish_vasp_domain_manager</a>(&new_account);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix)
}
Expand Down Expand Up @@ -2971,7 +2969,6 @@ Creates Preburn resource under account 'new_account_address'
<a href="DiemTimestamp.md#0x1_DiemTimestamp_assert_operating">DiemTimestamp::assert_operating</a>();
<a href="Roles.md#0x1_Roles_assert_treasury_compliance">Roles::assert_treasury_compliance</a>(creator_account);
<b>let</b> new_dd_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_dd_account);
<a href="Roles.md#0x1_Roles_new_designated_dealer_role">Roles::new_designated_dealer_role</a>(creator_account, &new_dd_account);
<a href="DesignatedDealer.md#0x1_DesignatedDealer_publish_designated_dealer_credential">DesignatedDealer::publish_designated_dealer_credential</a>&lt;CoinType&gt;(&new_dd_account, creator_account, add_all_currencies);
<a href="DualAttestation.md#0x1_DualAttestation_publish_credential">DualAttestation::publish_credential</a>(&new_dd_account, creator_account, human_name);
Expand Down Expand Up @@ -3065,7 +3062,6 @@ all available currencies in the system will also be added.
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
<a href="Roles.md#0x1_Roles_new_parent_vasp_role">Roles::new_parent_vasp_role</a>(creator_account, &new_account);
<a href="VASP.md#0x1_VASP_publish_parent_vasp_credential">VASP::publish_parent_vasp_credential</a>(&new_account, creator_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="DualAttestation.md#0x1_DualAttestation_publish_credential">DualAttestation::publish_credential</a>(&new_account, creator_account, human_name);
<a href="VASPDomain.md#0x1_VASPDomain_publish_vasp_domains">VASPDomain::publish_vasp_domains</a>(&new_account);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix);
Expand Down Expand Up @@ -3166,7 +3162,6 @@ also be added. This account will be a child of <code>creator</code>, which must
parent,
&new_account,
);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix);
<a href="DiemAccount.md#0x1_DiemAccount_add_currencies_for_account">add_currencies_for_account</a>&lt;Token&gt;(&new_account, add_all_currencies);
}
Expand Down Expand Up @@ -4763,7 +4758,6 @@ Create a Validator account
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
// The dr_account account is verified <b>to</b> have the diem root role in `<a href="Roles.md#0x1_Roles_new_validator_role">Roles::new_validator_role</a>`
<a href="Roles.md#0x1_Roles_new_validator_role">Roles::new_validator_role</a>(dr_account, &new_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="ValidatorConfig.md#0x1_ValidatorConfig_publish">ValidatorConfig::publish</a>(&new_account, dr_account, human_name);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix)
}
Expand Down Expand Up @@ -4844,7 +4838,6 @@ Create a Validator Operator account
<b>let</b> new_account = <a href="DiemAccount.md#0x1_DiemAccount_create_signer">create_signer</a>(new_account_address);
// The dr_account is verified <b>to</b> have the diem root role in `<a href="Roles.md#0x1_Roles_new_validator_operator_role">Roles::new_validator_operator_role</a>`
<a href="Roles.md#0x1_Roles_new_validator_operator_role">Roles::new_validator_operator_role</a>(dr_account, &new_account);
<a href="../../../../../../../move-stdlib/docs/Event.md#0x1_Event_publish_generator">Event::publish_generator</a>(&new_account);
<a href="ValidatorOperatorConfig.md#0x1_ValidatorOperatorConfig_publish">ValidatorOperatorConfig::publish</a>(&new_account, dr_account, human_name);
<a href="DiemAccount.md#0x1_DiemAccount_make_account">make_account</a>(&new_account, auth_key_prefix)
}
Expand Down
1 change: 1 addition & 0 deletions language/diem-framework/core/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ The Move modules in the Diem Framework can be bucketed in to a couple categories
- [`0x1::Errors`](../../../../../../../move-stdlib/docs/Errors.md#0x1_Errors)
- [`0x1::Event`](../../../../../../../move-stdlib/docs/Event.md#0x1_Event)
- [`0x1::FixedPoint32`](../../../../../../../move-stdlib/docs/FixedPoint32.md#0x1_FixedPoint32)
- [`0x1::GUID`](../../../../../../../move-stdlib/docs/GUID.md#0x1_GUID)
- [`0x1::Genesis`](Genesis.md#0x1_Genesis)
- [`0x1::Hash`](../../../../../../../move-stdlib/docs/Hash.md#0x1_Hash)
- [`0x1::NetworkIdentity`](NetworkIdentity.md#0x1_NetworkIdentity)
Expand Down
Loading

0 comments on commit ddc08b8

Please sign in to comment.