func (this *StellarAddressManager) createDatas(accCount int, createFilePath string) error { if stellarwebsocket.StellarWSInstance == nil { stellarwebsocket.InitStellarWSInstance() } this.StrAddrs = make([]*StellarAddressDefine, accCount) f, err := os.OpenFile(createFilePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModeType) defer f.Close() if err != nil { panic(err.Error()) } for i := 0; i < accCount; i++ { retMap, err := stellarwebsocket.StellarWSInstance.CreateUser() if err == nil { result, ok := retMap["result"] if ok { status, ok := result.(map[string]interface{})["status"] if ok { if status.(string) == "success" { // 创建账号成功 account_id, _ := result.(map[string]interface{})["account_id"] master_seed, _ := result.(map[string]interface{})["master_seed"] output := fmt.Sprintf("[ StellarAddressManager:createDatas() ]\r\n\taccount_id = %s ; master_seed = %s\r\n\r\n", account_id.(string), master_seed.(string)) fmt.Printf(output) _, err = f.WriteString(output) if err != nil { return err } this.StrAddrs[i] = &StellarAddressDefine{ PublicAddress: account_id.(string), PrivateSeed: master_seed.(string), } } } else { i-- } } else { i-- } } else { i-- } } return nil }
func (this *StellarAddressManager) checkBalance(addr string) (uint64, error) { if stellarwebsocket.StellarWSInstance == nil { stellarwebsocket.InitStellarWSInstance() } retMap, err := stellarwebsocket.StellarWSInstance.GetBalance(addr) // fmt.Println("[ StellarBalanceListener:checkBalance() ] = ", retMap) if err == nil { result, ok := retMap["result"] if ok { status, ok := result.(map[string]interface{})["status"] if ok { if status.(string) == "success" { //账号已经存在 account_data, _ := result.(map[string]interface{})["account_data"] balance, _ := account_data.(map[string]interface{})["Balance"] b, err := strconv.ParseUint(balance.(string), 10, 64) return b, err } else { error_message, ok := result.(map[string]interface{})["error_message"] if ok && error_message.(string) == "Account not found." { return 0, nil } else { err = errors.New("Listen to " + addr + " has error -> Read undefined error message :" + error_message.(string)) } } } else { err = errors.New("Listen to " + addr + " has error -> Can not get 'result->status' form response body.") } } else { err = errors.New("Listen to " + addr + " has error -> Can not get 'result' form response body.") } } fmt.Println("[ StellarBalanceListener:checkBalance() ] = ", err) return 0, err }