Skip to content

Commit

Permalink
Fix treasury account on reset scripts (#910)
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Mindov <[email protected]>
  • Loading branch information
rokn authored Oct 12, 2023
1 parent 9eb5524 commit b96b334
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
22 changes: 10 additions & 12 deletions scripts/bridge/setup/from-config/cmd/setup-from-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func main() {
privateKey := flag.String("privateKey", "0x0", "Hedera Private Key")
accountID := flag.String("accountID", "0.0", "Hedera Account ID")
network := flag.String("network", "testnet", "Hedera Network Type")
members := flag.Int("members", 1, "The count of the members")
memberPrivateKeys := flag.String("memberPrivateKeys", "", "Member private keys array, seperated by ','")
adminKey := flag.String("adminKey", "", "The admin key")
configPath := flag.String("configPath", "scripts/bridge/setup/extend-config/extended-bridge.yml", "Path to the 'bridge.yaml' config file")
Expand All @@ -63,6 +62,8 @@ func main() {
prKeysSlice := strings.Split(*memberPrivateKeys, ",")
var hederaPrivateKeys []hedera.PrivateKey

members := len(prKeysSlice)

// element [0] can be empty string if the user does not provide any private keys
if prKeysSlice[0] != "" {
for i := 0; i < len(prKeysSlice); i++ {
Expand All @@ -74,16 +75,16 @@ func main() {
}
}

treshold := uint(math.Ceil(float64(*members) * float64(0.51)))
treshold := uint(math.Ceil(float64(members) * 0.51))

validateArguments(privateKey, accountID, adminKey, members, configPath, network)
validateArguments(privateKey, accountID, adminKey, configPath, network)
if *network == "testnet" {
hederaNetworkId = HederaTestnetNetworkId
} else {
hederaNetworkId = HederaMainnetNetworkId
}
parsedBridgeCfgForDeploy := parseExtendedBridge(configPath)
bridgeDeployResult := deployBridge(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, treshold, parsedBridgeCfgForDeploy)
bridgeDeployResult := deployBridge(privateKey, accountID, adminKey, network, &members, hederaPrivateKeys, treshold, parsedBridgeCfgForDeploy)
createAndAssociateTokens(
&treshold,
bridgeDeployResult,
Expand Down Expand Up @@ -196,24 +197,21 @@ func createAndAssociateWrappedTokens(network uint64, networkInfo *parser.Network
fmt.Printf("Creating Hedera Wrapped Fungible Token based on info of token with address [%s] ...\n", tokenAddress)
tokenId, err := wrappedFungibleCreate.WrappedFungibleToken(
client,
client.GetOperatorAccountID(),
*bridgeDeployResult.BridgeAccountID,
client.GetOperatorPublicKey(),
supplyKey,
bridgeDeployResult.MembersPrivateKeys,
tokenInfo.Name,
tokenInfo.Symbol,
tokenInfo.Decimals,
tokenInfo.Supply,
0,
)
if err != nil {
fmt.Printf("[ERROR] Failed to Create Hedera Wrapped Fungible Token based on info of token [%s]. Error: [%s]\n", tokenAddress, err)
continue
}
fmt.Printf("Successfully Created Hedera Wrapped Fungible Token with address [%s] based on info of token [%s]\n", tokenId.String(), tokenAddress)
err = associateToken(tokenId, client, *bridgeDeployResult.BridgeAccountID, "Bridge", bridgeDeployResult.MembersPrivateKeys)
if err == nil {
ExtendedBridge.Networks[network].Tokens.Fungible[tokenAddress].Networks[hederaNetworkId] = tokenId.String()
}
ExtendedBridge.Networks[network].Tokens.Fungible[tokenAddress].Networks[hederaNetworkId] = tokenId.String()
}
}

Expand Down Expand Up @@ -323,8 +321,8 @@ func parseParams(content []byte, topicId *string, executorId *string, nodeAccoun
return content, topicIdParsed, executor, nodeAccount
}

func validateArguments(privateKey *string, accountID *string, adminKey *string, members *int, configPath *string, network *string) {
err := bridgeSetup.ValidateArguments(privateKey, accountID, adminKey, members)
func validateArguments(privateKey *string, accountID *string, adminKey *string, configPath *string, network *string) {
err := bridgeSetup.ValidateArguments(privateKey, accountID, adminKey)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/bridge/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type DeployResult struct {
func Deploy(privateKey *string, accountID *string, adminKey *string, network *string, members *int, previousPrivateKeys []hedera.PrivateKey, treshold uint) DeployResult {
result := DeployResult{}

err := ValidateArguments(privateKey, accountID, adminKey, members)
err := ValidateArguments(privateKey, accountID, adminKey)
if err != nil {
result.Error = err
return result
Expand Down Expand Up @@ -167,7 +167,7 @@ func Deploy(privateKey *string, accountID *string, adminKey *string, network *st
return result
}

func ValidateArguments(privateKey *string, accountID *string, adminKey *string, members *int) error {
func ValidateArguments(privateKey *string, accountID *string, adminKey *string) error {
if *privateKey == "0x0" {
return errors.New("private key was not provided")
}
Expand Down

0 comments on commit b96b334

Please sign in to comment.