Warm tip: This article is reproduced from serverfault.com, please click

How to create Account with ID in corda

发布于 2020-12-01 07:35:23

I am using accounts library for my project in Corda. I need to create accounts with custom IDs for the account. Till Now I am creating accounts using the CreateAccount Flow which accepts only one parameter which is account name. the Code for the Create Account Flow is as follow:

@InitiatingFlow
@StartableByRPC
public class CreateAccountFlow extends FlowLogic<String> {
    private String accountName;
//    private UUID userID;
    public CreateAccountFlow(String accountName) {
        this.accountName = accountName;

    }

    @Override
    @Suspendable
    public String call() throws FlowException {
        StateAndRef<AccountInfo> newAccount = null;
        try {
//            newAccount = getServiceHub().cordaService(KeyManagementBackedAccountService.class).createAccount(accountName).get();
            newAccount =(StateAndRef<AccountInfo>) subFlow(new CreateAccount(accountName));

        } catch (Exception e) {
            e.printStackTrace();
        }
        AccountInfo acc = newAccount.getState().getData();
        return "Account "+acc.getName()+ " Created";
    }
}

Is there any way so I can create Account with ID and Name both??

Questioner
Vishwa Dayal
Viewed
0
Adel Rustum 2020-12-01 23:52:55

Write your own version of the flow which extends CreateAccount and has a public constructor that accepts both name and identifier; as you can see here, the flow already has that constructor but it's marked as private.