Skip to content

Commit

Permalink
Revert "[account] Add create_delegate_account function (#31)"
Browse files Browse the repository at this point in the history
This reverts commit a225d41.
  • Loading branch information
nkysg committed Mar 2, 2023
1 parent 77259bf commit 7608046
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 181 deletions.
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: E9144252A3E50D7727A1E1A0DD76494580D66DD68C46C9625CC1042087A4D5BE
source_digest: 393B652869BD1D391A88E8A7874298F9AEEF181C4955513FE7D69C00899AD3A2
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file modified build/StarcoinFramework/bytecode_modules/Account.mv
Binary file not shown.
68 changes: 0 additions & 68 deletions build/StarcoinFramework/docs/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ The module for the account resource that governs every account
- [Function `create_signer`](#0x1_Account_create_signer)
- [Function `create_account_with_initial_amount`](#0x1_Account_create_account_with_initial_amount)
- [Function `create_account_with_initial_amount_v2`](#0x1_Account_create_account_with_initial_amount_v2)
- [Function `create_delegate_account`](#0x1_Account_create_delegate_account)
- [Function `deposit_to_self`](#0x1_Account_deposit_to_self)
- [Function `deposit`](#0x1_Account_deposit)
- [Function `deposit_with_metadata`](#0x1_Account_deposit_with_metadata)
Expand Down Expand Up @@ -78,7 +77,6 @@ The module for the account resource that governs every account


<pre><code><b>use</b> <a href="Authenticator.md#0x1_Authenticator">0x1::Authenticator</a>;
<b>use</b> <a href="BCS.md#0x1_BCS">0x1::BCS</a>;
<b>use</b> <a href="CoreAddresses.md#0x1_CoreAddresses">0x1::CoreAddresses</a>;
<b>use</b> <a href="Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="Event.md#0x1_Event">0x1::Event</a>;
Expand Down Expand Up @@ -478,16 +476,6 @@ Message for accept token events



<a name="0x1_Account_ADDRESS_LENGTH"></a>

The address bytes length


<pre><code><b>const</b> <a href="Account.md#0x1_Account_ADDRESS_LENGTH">ADDRESS_LENGTH</a>: u64 = 16;
</code></pre>



<a name="0x1_Account_CONTRACT_ACCOUNT_AUTH_KEY_PLACEHOLDER"></a>


Expand Down Expand Up @@ -1109,62 +1097,6 @@ reserved address for the MoveVM.



</details>

<a name="0x1_Account_create_delegate_account"></a>

## Function `create_delegate_account`

Generate an new address and create a new account, then delegate the account and return the new account address and <code><a href="Account.md#0x1_Account_SignerCapability">SignerCapability</a></code>


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_create_delegate_account">create_delegate_account</a>(sender: &signer): (<b>address</b>, <a href="Account.md#0x1_Account_SignerCapability">Account::SignerCapability</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_create_delegate_account">create_delegate_account</a>(sender: &signer) : (<b>address</b>, <a href="Account.md#0x1_Account_SignerCapability">SignerCapability</a>) <b>acquires</b> <a href="Account.md#0x1_Account_Balance">Balance</a>, <a href="Account.md#0x1_Account">Account</a> {
<b>let</b> sender_address = <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(sender);
<b>let</b> sequence_number = <a href="Account.md#0x1_Account_sequence_number">Self::sequence_number</a>(sender_address);
// <b>use</b> stc balance <b>as</b> part of seed, just for new <b>address</b> more random.
<b>let</b> stc_balance = <a href="Account.md#0x1_Account_balance">Self::balance</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(sender_address);

<b>let</b> seed_bytes = <a href="BCS.md#0x1_BCS_to_bytes">BCS::to_bytes</a>(&sender_address);
<a href="Vector.md#0x1_Vector_append">Vector::append</a>(&<b>mut</b> seed_bytes, <a href="BCS.md#0x1_BCS_to_bytes">BCS::to_bytes</a>(&sequence_number));
<a href="Vector.md#0x1_Vector_append">Vector::append</a>(&<b>mut</b> seed_bytes, <a href="BCS.md#0x1_BCS_to_bytes">BCS::to_bytes</a>(&stc_balance));

<b>let</b> seed_hash = <a href="Hash.md#0x1_Hash_sha3_256">Hash::sha3_256</a>(seed_bytes);
<b>let</b> i = 0;
<b>let</b> address_bytes = <a href="Vector.md#0x1_Vector_empty">Vector::empty</a>();
<b>while</b> (i &lt; <a href="Account.md#0x1_Account_ADDRESS_LENGTH">ADDRESS_LENGTH</a>) {
<a href="Vector.md#0x1_Vector_push_back">Vector::push_back</a>(&<b>mut</b> address_bytes, *<a href="Vector.md#0x1_Vector_borrow">Vector::borrow</a>(&seed_hash,i));
i = i + 1;
};
<b>let</b> new_address = <a href="BCS.md#0x1_BCS_to_address">BCS::to_address</a>(address_bytes);
<a href="Account.md#0x1_Account_create_account_with_address">Self::create_account_with_address</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(new_address);
<b>let</b> new_signer = <a href="Account.md#0x1_Account_create_signer">Self::create_signer</a>(new_address);
(new_address, <a href="Account.md#0x1_Account_remove_signer_capability">Self::remove_signer_capability</a>(&new_signer))
}
</code></pre>



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



</details>

<a name="0x1_Account_deposit_to_self"></a>
Expand Down
Binary file modified build/StarcoinFramework/source_maps/Account.mvsm
Binary file not shown.
17 changes: 0 additions & 17 deletions integration-tests/account/delegate_account.exp

This file was deleted.

62 changes: 0 additions & 62 deletions integration-tests/account/delegate_account.move

This file was deleted.

33 changes: 0 additions & 33 deletions sources/Account.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Account {
use StarcoinFramework::CoreAddresses;
use StarcoinFramework::Errors;
use StarcoinFramework::STC::{Self, STC};
use StarcoinFramework::BCS;

spec module {
pragma verify = false;
Expand Down Expand Up @@ -133,9 +132,6 @@ module Account {
const DUMMY_AUTH_KEY:vector<u8> = x"0000000000000000000000000000000000000000000000000000000000000000";
// cannot be dummy key, or empty key
const CONTRACT_ACCOUNT_AUTH_KEY_PLACEHOLDER:vector<u8> = x"0000000000000000000000000000000000000000000000000000000000000001";

/// The address bytes length
const ADDRESS_LENGTH: u64 = 16;

/// A one-way action, once SignerCapability is removed from signer, the address cannot send txns anymore.
/// This function can only called once by signer.
Expand Down Expand Up @@ -283,35 +279,6 @@ module Account {
pragma verify = false;
}

/// Generate an new address and create a new account, then delegate the account and return the new account address and `SignerCapability`
public fun create_delegate_account(sender: &signer) : (address, SignerCapability) acquires Balance, Account {
let sender_address = Signer::address_of(sender);
let sequence_number = Self::sequence_number(sender_address);
// use stc balance as part of seed, just for new address more random.
let stc_balance = Self::balance<STC>(sender_address);

let seed_bytes = BCS::to_bytes(&sender_address);
Vector::append(&mut seed_bytes, BCS::to_bytes(&sequence_number));
Vector::append(&mut seed_bytes, BCS::to_bytes(&stc_balance));

let seed_hash = Hash::sha3_256(seed_bytes);
let i = 0;
let address_bytes = Vector::empty();
while (i < ADDRESS_LENGTH) {
Vector::push_back(&mut address_bytes, *Vector::borrow(&seed_hash,i));
i = i + 1;
};
let new_address = BCS::to_address(address_bytes);
Self::create_account_with_address<STC>(new_address);
let new_signer = Self::create_signer(new_address);
(new_address, Self::remove_signer_capability(&new_signer))
}

spec create_delegate_account {
pragma verify = false;
//TODO write spec
}

/// Deposits the `to_deposit` token into the self's account balance
public fun deposit_to_self<TokenType: store>(account: &signer, to_deposit: Token<TokenType>)
acquires Account, Balance, AutoAcceptToken {
Expand Down

0 comments on commit 7608046

Please sign in to comment.