When participating in the SNS launch, how is the account for each person's transfer determined?

When participating in the SNS launch, I found that everyone transfers money to different accounts. I am curious what rules are used to do this. I can’t find it in the SNS code. Can anyone help me?

One of the hints I could find in the code is here. It uses the (very common) pattern of using the participant’s Principal as the subaccount. The account IDs are then calculated from the pair (swap canister, participant)

I didn’t understand how he generated the account

  let account = Account {
            owner: this_canister.get().0,
            subaccount: Some(principal_to_subaccount(&buyer)),

The specific generation method of this code is not understood

That’s just the convention. If you want the source code of that, have a look at the source of AccountIdentifier::new and Subaccount::from::<Principal>

I don’t understand it very well, because the code I am good at is Python

I didn’t understand how he generated the account

It is the swap canister id as the account owner and the buyer principal id as the subaccount using this function.

Here is where the swap canister checks the balance of that account

Here is the specification for the account-identifier: Internet Computer Loading.

Here is an implementation in the Dart language, more similar to Python: ic_tools/lib/src/common.dart at 3c4187115015d7834911bf3fa5cb0c901bab304d · levifeldman/ic_tools · GitHub

I follow the method you said, the sending address is incorrect

def convert_wallet_address_to_bytes_array(wallet_address):
    final_text = []
    for x in range(int(len(wallet_address) / 2)):
        my_hexdata = wallet_address[x*2:x*2+2]
    return final_text    


Convert the wallet principal to a subaccount byte array.
ic_tools/lib/src/common.dart at 3c4187115015d7834911bf3fa5cb0c901bab304d · levifeldman/ic_tools · GitHub.