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

fix(903): wrong init hedera client while associate tokens to account #908

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions scripts/token/native/create/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
setSupplyKey := flag.Bool("setSupplyKey", true, "Sets supply key to be the deployer")

fmt.Println("-----------Start-----------")
client := client.Init(*privateKey, *accountID, *network)
cl := client.Init(*privateKey, *accountID, *network)

mirrorNodeConfigByNetwork := map[uint64]config.MirrorNode{
HederaMainnetNetworkId: {
Expand Down Expand Up @@ -99,8 +99,8 @@ func main() {
}

tokenId, err := create.CreateNativeFungibleToken(
client,
client.GetOperatorAccountID(),
cl,
cl.GetOperatorAccountID(),
*tokenName,
*tokenSymbol,
*decimals,
Expand All @@ -117,36 +117,37 @@ func main() {
panic(err)
}

receipt, err := associate.TokenToAccountWithCustodianKey(client, *tokenId, bridgeIDFromString, custodianKey)
receipt, err := associate.TokenToAccountWithCustodianKey(cl, *tokenId, bridgeIDFromString, custodianKey)
if err != nil {
panic(err)
}
fmt.Println("Token ID:", tokenId)
fmt.Println("Associate transaction status:", receipt.Status)

// associate token with members
for _, memberPrKey := range membersPublicKey {
accounts, err := mirrorNodeClient.GetAccountByPublicKey(memberPrKey.String())
for memberPubKeyIndex, memberPubKey := range membersPublicKey {
accounts, err := mirrorNodeClient.GetAccountByPublicKey(memberPubKey.String())
if err != nil {
panic(fmt.Errorf("cannot obtain account by public key: %w", err))
}

if len(accounts.Accounts) == 0 {
panic("cannot find account by public key")
} else if len(accounts.Accounts) != 1 {
panic("multiple accounts found for public key - " + memberPrKey.String())
panic("multiple accounts found for public key - " + memberPubKey.String())
}

hAccount, err := hedera.AccountIDFromString(accounts.Accounts[0].Account)
if err != nil {
panic(fmt.Errorf("cannot convert string to hedera account: %w", err))
}

receipt, err := associate.TokenToAccount(client, *tokenId, hAccount)
hClient := client.Init(membersSlice[memberPubKeyIndex], hAccount.String(), *network)
tokenToAccountReceipt, err := associate.TokenToAccount(hClient, *tokenId, hAccount)
if err != nil {
panic(fmt.Errorf("failed to associate token to account: %w", err))
}
fmt.Printf("Account[%s] associated with token[%s], tx status: %s\n",
hAccount.String(), tokenId.String(), receipt.Status)
hAccount.String(), tokenId.String(), tokenToAccountReceipt.Status)
}
}