/
add_migration_addresses.go
37 lines (34 loc) · 1.39 KB
/
add_migration_addresses.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"strconv"
"strings"
"github.com/insolar/assured-ledger/ledger-core/application/api/sdk"
)
func addMigrationAddresses(adminUrls []string, publicUrls []string, memberKeysDirPath string, addressesPath string, shardsCount int) {
insSDK, err := sdk.NewSDK(adminUrls, publicUrls, memberKeysDirPath, sdk.DefaultOptions)
check("SDK is not initialized: ", err)
var filename string
// method AddMigrationAddresses in contract use only 10 shards in one call
for i := 0; i*10 < shardsCount; i++ {
if shardsCount == 10 {
filename = addressesPath
} else {
addrPath := strings.Split(addressesPath, ".json")
// filename match with files, generated by generator utility (from insolar/migrationAddressGenerator)
filename = addrPath[0] + "_" + strconv.Itoa(i) + ".json"
}
rawConf, err := ioutil.ReadFile(filepath.Clean(filename))
check("Error while reading file: ", err)
var addresses []string
err = json.Unmarshal(rawConf, &addresses)
check(fmt.Sprintf("Error while unmarshal content of file %s to list of addresses: ", filename), err)
_, err = insSDK.AddMigrationAddresses(addresses)
check(fmt.Sprintf("Error while adding addresses from file %s: ", filename), err)
fmt.Printf("Addresses to shards with indexes %d-%d were added successfully\n", i*10, i*10+9)
}
fmt.Println("All addresses were added successfully")
}