| 165 | } |
| 166 | |
| 167 | func getMiningInfo(ctx context.Context, client *ethclient.Client, contract common.Address, shardIdx uint64) ([]interface{}, error) { |
| 168 | uint256Type, _ := abi.NewType("uint256", "", nil) |
| 169 | dataField, _ := abi.Arguments{{Type: uint256Type}}.Pack(new(big.Int).SetUint64(shardIdx)) |
| 170 | h := crypto.Keccak256Hash([]byte(`infos(uint256)`)) |
| 171 | calldata := append(h[0:4], dataField...) |
| 172 | msg := ethereum.CallMsg{ |
| 173 | To: &contract, |
| 174 | Data: calldata, |
| 175 | } |
| 176 | bs, err := client.CallContract(ctx, msg, nil) |
| 177 | if err != nil { |
| 178 | lg.Error("Failed to call contract", "error", err.Error()) |
| 179 | return nil, err |
| 180 | } |
| 181 | res, _ := abi.Arguments{ |
| 182 | {Type: uint256Type}, |
| 183 | {Type: uint256Type}, |
| 184 | {Type: uint256Type}, |
| 185 | }.UnpackValues(bs) |
| 186 | if res == nil || len(res) < 3 { |
| 187 | lg.Error("Query mining info by shard", "error", "invalid result", "result", res) |
| 188 | return nil, fmt.Errorf("invalid result: %v", res) |
| 189 | } |
| 190 | return res, nil |
| 191 | } |
| 192 | |
| 193 | func createDataFile(cfg *storage.StorageConfig, shardIdxList []uint64, datadir string, encodingType int) ([]string, error) { |
| 194 | lg.Info("Creating data files", "shardIdxList", shardIdxList, "dataDir", datadir) |