From 705be7737dc8edc47bcff43a9fa27ce542adb0cf Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Fri, 14 Feb 2020 17:47:26 -0800 Subject: [PATCH 01/36] add wallet feature --- core/wallet/signature.go | 136 +++++++++++++ core/wallet/transaction.go | 391 +++++++++++++++++++++++++++++++++++++ core/wallet/util.go | 118 +++++++++++ core/wallet/wallet.go | 204 +++++++++++++++++++ go.mod | 6 +- go.sum | 82 ++++++++ 6 files changed, 935 insertions(+), 2 deletions(-) create mode 100644 core/wallet/signature.go create mode 100644 core/wallet/transaction.go create mode 100644 core/wallet/util.go create mode 100644 core/wallet/wallet.go diff --git a/core/wallet/signature.go b/core/wallet/signature.go new file mode 100644 index 000000000..302e36095 --- /dev/null +++ b/core/wallet/signature.go @@ -0,0 +1,136 @@ +package wallet + +import ( + "crypto" + "crypto/ecdsa" + "crypto/rand" + "encoding/asn1" + "errors" + "math/big" + "time" + + exPb "github.com/tron-us/go-btfs-common/protos/exchange" + ledgerPb "github.com/tron-us/go-btfs-common/protos/ledger" + corePb "github.com/tron-us/go-btfs-common/protos/protocol/core" + + eth "github.com/ethereum/go-ethereum/crypto" + "github.com/golang/protobuf/proto" +) + +type EcdsaSignature struct { + R, S *big.Int +} + +var ( + ErrTransactionParam = errors.New("transaction is nil") + ErrChannelStateParam = errors.New("channelState is nil") + ErrChannelCommitParam = errors.New("channelCommit is nil") + ErrTypeParam = errors.New("wrong type") +) + +//Sign a Transaction, ChannelState, ChannelCommit in exchange proto or tron proto or ledger proto. +//parameter 'in' can be Transaction, ChannelState, ChannelCommit, return signature. +func Sign(in interface{}, key *ecdsa.PrivateKey) ([]byte, error) { + switch in.(type) { + case *exPb.TronTransaction: + transaction := in.(*exPb.TronTransaction) + if transaction == nil { + return nil, ErrTransactionParam + } + + if transaction.GetRawData().Timestamp == 0 { + transaction.GetRawData().Timestamp = time.Now().UnixNano() / 1000000 + } + + rawData, err := proto.Marshal(transaction.GetRawData()) + if err != nil { + return nil, err + } + return SignTron(rawData, key) + + case *corePb.Transaction: + transaction := in.(*corePb.Transaction) + if transaction == nil { + return nil, ErrTransactionParam + } + + if transaction.GetRawData().Timestamp == 0 { + transaction.GetRawData().Timestamp = time.Now().UnixNano() / 1000000 + } + + rawData, err := proto.Marshal(transaction.GetRawData()) + if err != nil { + return nil, err + } + return SignTron(rawData, key) + + case *ledgerPb.ChannelState: + channelState := in.(*ledgerPb.ChannelState) + if channelState == nil { + return nil, ErrChannelStateParam + } + + raw, err := proto.Marshal(channelState) + if err != nil { + return nil, err + } + return SignChannel(raw, key) + + case *ledgerPb.ChannelCommit: + channelCommit := in.(*ledgerPb.ChannelCommit) + if channelCommit == nil { + return nil, ErrChannelCommitParam + } + + raw, err := proto.Marshal(channelCommit) + if err != nil { + return nil, err + } + return SignChannel(raw, key) + + default: + return nil, ErrTypeParam + } +} + +//Tron' Sign function, return signature and error. +func SignTron(rawData []byte, key *ecdsa.PrivateKey) ([]byte, error) { + hash, err := Hash(rawData) + if err != nil { + return nil, err + } + + signature, err := eth.Sign(hash, key) + if err != nil { + return nil, err + } + return signature, nil +} + +//Channel' sign function, return signature and error. +func SignChannel(raw []byte, key *ecdsa.PrivateKey) ([]byte, error) { + hash, err := Hash(raw) + if err != nil { + return nil, err + } + + signature, err := key.Sign(rand.Reader, hash, crypto.SHA256) + if err != nil { + return nil, err + } + return signature, nil +} + +// Verify signature. +func Verify(publicKey, data, signature []byte) (bool, error) { + pubKey, err := eth.UnmarshalPubkey(publicKey) + if err != nil { + return false, err + } + a := EcdsaSignature{} + _, err = asn1.Unmarshal(signature, &a) + if err != nil { + return false, nil + } + return ecdsa.Verify(pubKey, data, a.R, a.S), nil +} diff --git a/core/wallet/transaction.go b/core/wallet/transaction.go new file mode 100644 index 000000000..d77b88707 --- /dev/null +++ b/core/wallet/transaction.go @@ -0,0 +1,391 @@ +package wallet + +import ( + "context" + "crypto/ecdsa" + "encoding/hex" + "errors" + "fmt" + "time" + + escrowPb "github.com/tron-us/go-btfs-common/protos/escrow" + exPb "github.com/tron-us/go-btfs-common/protos/exchange" + ledgerPb "github.com/tron-us/go-btfs-common/protos/ledger" + tronPb "github.com/tron-us/go-btfs-common/protos/protocol/api" + corePb "github.com/tron-us/go-btfs-common/protos/protocol/core" + "github.com/tron-us/go-btfs-common/utils/grpc" +) + +var ( + ErrInsufficientExchangeBalanceOnTron = errors.New("exchange balance on Tron network is not sufficient") + ErrInsufficientUserBalanceOnTron = errors.New(fmt.Sprint("User balance on tron network is not sufficient.")) + ErrInsufficientUserBalanceOnLedger = errors.New("rpc error: code = ResourceExhausted desc = NSF") + ErrInsufficientExchangeBalanceOnLedger = errors.New("exchange balance on Private Ledger is not sufficient") +) + +// Do the deposit action, integrate exchange's PrepareDeposit and Deposit API. +func Deposit(ledgerAddr []byte, amount int64, privateKey *ecdsa.PrivateKey) (*exPb.PrepareDepositResponse, error) { + log.Debug("Deposit begin!") + //PrepareDeposit + prepareResponse, err := PrepareDeposit(ledgerAddr, amount) + if err != nil { + log.Error(fmt.Sprintf("PrepareDeposit error, reasons: [%v]", err)) + return nil, err + } + if prepareResponse.Response.Code != exPb.Response_SUCCESS { + log.Error(fmt.Sprintf("PrepareDeposit failed, reasons: [%s]", string(prepareResponse.Response.ReturnMessage))) + return prepareResponse, errors.New(string(prepareResponse.Response.ReturnMessage)) + } + log.Debug(fmt.Sprintf("PrepareDeposit success, id: [%d]", prepareResponse.GetId())) + + //Do the DepositRequest. + depositResponse, err := DepositRequest(prepareResponse, privateKey) + if err != nil { + log.Error(fmt.Sprintf("Deposit error, reasons: [%v]", err)) + return prepareResponse, err + } + if depositResponse.Response.Code != exPb.Response_SUCCESS { + log.Error(fmt.Sprintf("Deposit failed, reasons: [%s]", string(depositResponse.Response.ReturnMessage))) + return prepareResponse, errors.New(string(depositResponse.Response.ReturnMessage)) + } + log.Debug(fmt.Sprintf("Call Deposit API success, id: [%d]", prepareResponse.GetId())) + + // Doing confirm deposit. + go func() { + ConfirmDepositProcess(prepareResponse, privateKey) + }() + + log.Debug("Deposit end!") + return prepareResponse, nil +} + +// Call exchange's PrepareDeposit API. +func PrepareDeposit(ledgerAddr []byte, amount int64) (*exPb.PrepareDepositResponse, error) { + // Prepare to Deposit. + ctx := context.Background() + var err error + var prepareResponse *exPb.PrepareDepositResponse + err = grpc.ExchangeClient(exchangeService).WithContext(ctx, + func(ctx context.Context, client exPb.ExchangeClient) error { + prepareDepositRequest := &exPb.PrepareDepositRequest{Amount: amount, OutTxId: time.Now().UnixNano(), + UserAddress: ledgerAddr} + prepareResponse, err = client.PrepareDeposit(ctx, prepareDepositRequest) + if err != nil { + log.Error(fmt.Sprintf("PrepareDeposit error, reasons: [%v]", err)) + return err + } + return nil + }) + if err != nil { + return nil, err + } + return prepareResponse, nil +} + +// Call exchange's Deposit API +func DepositRequest(prepareResponse *exPb.PrepareDepositResponse, privateKey *ecdsa.PrivateKey) (*exPb.DepositResponse, error) { + // Sign Tron Transaction. + tronTransaction := prepareResponse.GetTronTransaction() + for range tronTransaction.GetRawData().GetContract() { + signature, err := Sign(tronTransaction, privateKey) + if err != nil { + return nil, err + } + tronTransaction.Signature = append(tronTransaction.GetSignature(), signature) + } + + ctx := context.Background() + var err error + var depositResponse *exPb.DepositResponse + err = grpc.ExchangeClient(exchangeService).WithContext(ctx, + func(ctx context.Context, client exPb.ExchangeClient) error { + depositRequest := &exPb.DepositRequest{Id: prepareResponse.GetId(), SignedTronTransaction: tronTransaction} + + depositResponse, err = client.Deposit(ctx, depositRequest) + if err != nil { + log.Error(fmt.Sprintf("Deposit error, reasons: [%v]", err)) + return err + } + return nil + }) + if err != nil { + return nil, err + } + return depositResponse, nil +} + +// Continuous call ConfirmDeposit until it responses a FAILED or SUCCESS. +func ConfirmDepositProcess(prepareResponse *exPb.PrepareDepositResponse, privateKey *ecdsa.PrivateKey) { + ctx := context.Background() + log.Debug(fmt.Sprintf("[Id:%d] ConfirmDepositProcess begin.", prepareResponse.GetId())) + + // Continuous call ConfirmDeposit until it responses a FAILED or SUCCESS. + for time.Now().UnixNano()/1e6 < (prepareResponse.GetTronTransaction().GetRawData().GetExpiration() + 240*1000) { + time.Sleep(10 * time.Second) + + // ConfirmDeposit after 1min, because watcher need wait for 1min to confirm tron transaction. + if time.Now().UnixNano()/1e6 < (prepareResponse.GetTronTransaction().GetRawData().GetTimestamp() + 60*1000) { + continue + } + log.Debug(fmt.Sprintf("[Id:%d] ConfirmDeposit begin.", prepareResponse.GetId())) + + confirmDepositResponse, err := ConfirmDeposit(prepareResponse.GetId()) + if err != nil { + log.Error(fmt.Sprintf("[Id:%d]ConfirmDeposit error: %v", prepareResponse.GetId(), err)) + continue + } + if confirmDepositResponse.GetResponse().GetCode() == exPb.Response_TRANSACTION_PENDING { + log.Debug(fmt.Sprintf("[Id:%d]TronTransaction is PENDING.", prepareResponse.GetId())) + continue + } + if confirmDepositResponse.GetResponse().GetCode() == exPb.Response_TRANSACTION_FAILED { + log.Info(fmt.Sprintf("[Id:%d]TronTransaction is FAILED, deposit failed.", prepareResponse.GetId())) + return + } + if confirmDepositResponse.GetResponse().GetCode() == exPb.Response_SUCCESS { + signSuccessChannelState := confirmDepositResponse.GetSuccessChannelState() + if signSuccessChannelState != nil { + toSignature, err := Sign(signSuccessChannelState.GetChannel(), privateKey) + if err != nil { + log.Error(fmt.Sprintf("[Id:%d] Sign SuccessChannelState error: %v", prepareResponse.GetId(), err)) + return + } + signSuccessChannelState.ToSignature = toSignature + } else { + log.Error(fmt.Sprintf("[Id:%d] SignSuccessChannelState is nil", prepareResponse.GetId())) + return + } + + err = grpc.EscrowClient(escrowService).WithContext(ctx, + func(ctx context.Context, client escrowPb.EscrowServiceClient) error { + _, err = client.CloseChannel(ctx, signSuccessChannelState) + if err != nil { + log.Error(fmt.Sprintf("[Id:%d] Close SuccessChannelState error: %v", prepareResponse.GetId(), err)) + return err + } + return nil + }) + if err != nil { + return + } + + log.Info(fmt.Sprintf("[Id:%d] Close SuccessChannelState succeed.", prepareResponse.GetId())) + return + } + } + if time.Now().UnixNano()/1e6 >= (prepareResponse.GetTronTransaction().GetRawData().GetExpiration() + 240*1000) { + log.Error(fmt.Sprintf("[Id:%d] Didn't get the tron transaction results until the expiration time.", + prepareResponse.GetId())) + } +} + +// Call exchange's ConfirmDeposit API. +func ConfirmDeposit(logId int64) (*exPb.ConfirmDepositResponse, error) { + ctx := context.Background() + var err error + var confirmDepositResponse *exPb.ConfirmDepositResponse + err = grpc.ExchangeClient(exchangeService).WithContext(ctx, + func(ctx context.Context, client exPb.ExchangeClient) error { + confirmDepositRequest := &exPb.ConfirmDepositRequest{Id: logId} + confirmDepositResponse, err = client.ConfirmDeposit(ctx, confirmDepositRequest) + if err != nil { + log.Error(fmt.Sprintf("ConfirmDeposit failed, reasons: [%v]", err)) + return err + } + return nil + }) + if err != nil { + return nil, err + } + return confirmDepositResponse, nil +} + +// Do the withdraw action, integrate exchange's PrepareWithdraw and Withdraw API, return channel id and error. +// If Withdraw succeed, with return channel id and logInfo id, error is nil; otherwise will return error, channel id +// and logInfo id is 0. +func Withdraw(ledgerAddr, externalAddr []byte, amount int64, privateKey *ecdsa.PrivateKey) (int64, int64, error) { + log.Debug("Withdraw begin!") + outTxId := time.Now().UnixNano() + //PrepareWithdraw + prepareResponse, err := PrepareWithdraw(ledgerAddr, externalAddr, amount, outTxId) + if err != nil { + log.Error(fmt.Sprintf("Prepare withdraw error, reasons: [%v]", err)) + return 0, 0, err + } + if prepareResponse.Response.Code != exPb.Response_SUCCESS { + log.Error(fmt.Sprintf("Prepare withdraw failed, reasons: [%s]", string(prepareResponse.Response.ReturnMessage))) + return 0, 0, errors.New(string(prepareResponse.Response.ReturnMessage)) + } + log.Debug(fmt.Sprintf("Prepare withdraw success, id: [%d]", prepareResponse.GetId())) + + channelCommit := &ledgerPb.ChannelCommit{ + Payer: &ledgerPb.PublicKey{Key: ledgerAddr}, + Receiver: &ledgerPb.PublicKey{Key: prepareResponse.GetLedgerExchangeAddress()}, + Amount: amount, + PayerId: time.Now().UnixNano() + prepareResponse.GetId(), + } + //Sign channel commit. + signature, err := Sign(channelCommit, privateKey) + if err != nil { + log.Error(fmt.Sprintf("Sign error, reasons: [%v]", err)) + return 0, 0, err + } + + ctx := context.Background() + var channelId *ledgerPb.ChannelID + err = grpc.EscrowClient(escrowService).WithContext(ctx, + func(ctx context.Context, client escrowPb.EscrowServiceClient) error { + channelId, err = client.CreateChannel(ctx, + &ledgerPb.SignedChannelCommit{Channel: channelCommit, Signature: signature}) + if err != nil { + if err.Error() == ErrInsufficientUserBalanceOnLedger.Error() { + log.Error(fmt.Sprintf("[Addr:%s] balance on ledger is insufficient.", hex.EncodeToString(ledgerAddr))) + return ErrInsufficientUserBalanceOnLedger + } + log.Error(fmt.Sprintf("Create channel error, reasons: [%v]", err)) + return err + } + return nil + }) + if err != nil { + return 0, 0, err + } + log.Debug(fmt.Sprintf("CreateChannel success, channelId: [%d]", channelId.GetId())) + + //Do the WithdrawRequest. + withdrawResponse, err := WithdrawRequest(channelId, ledgerAddr, amount, prepareResponse, privateKey) + if err != nil { + log.Error(fmt.Sprintf("Withdraw error, reasons: [%v]", err)) + return 0, 0, err + } + if withdrawResponse.Response.Code != exPb.Response_SUCCESS { + log.Error(fmt.Sprintf("Withdraw failed, reasons: [%s]", string(withdrawResponse.Response.ReturnMessage))) + return 0, 0, errors.New(string(withdrawResponse.Response.ReturnMessage)) + } + log.Debug("Withdraw end!") + return channelId.Id, prepareResponse.GetId(), nil +} + +// Call exchange's Withdraw API +func PrepareWithdraw(ledgerAddr, externalAddr []byte, amount, outTxId int64) ( + *exPb.PrepareWithdrawResponse, error) { + ctx := context.Background() + var err error + var prepareResponse *exPb.PrepareWithdrawResponse + err = grpc.ExchangeClient(exchangeService).WithContext(ctx, + func(ctx context.Context, client exPb.ExchangeClient) error { + prepareWithdrawRequest := &exPb.PrepareWithdrawRequest{ + Amount: amount, OutTxId: outTxId, UserAddress: ledgerAddr, UserExternalAddress: externalAddr} + prepareResponse, err = client.PrepareWithdraw(ctx, prepareWithdrawRequest) + if err != nil { + log.Error(fmt.Sprintf("PrepareWithdraw error, reasons: [%v]", err)) + return err + } + log.Debug(prepareResponse) + return nil + }) + if err != nil { + log.Error("wallet PrepareWithdraw error: ", err) + return nil, err + } + + return prepareResponse, nil +} + +// Call exchange's PrepareWithdraw API +func WithdrawRequest(channelId *ledgerPb.ChannelID, ledgerAddr []byte, + amount int64, prepareResponse *exPb.PrepareWithdrawResponse, privateKey *ecdsa.PrivateKey) (*exPb.WithdrawResponse, + error) { + //make signed success channel state. + successChannelState := &ledgerPb.ChannelState{ + Id: channelId, + Sequence: 1, + From: &ledgerPb.Account{ + Address: &ledgerPb.PublicKey{ + Key: ledgerAddr, + }, + Balance: 0, + }, + To: &ledgerPb.Account{ + Address: &ledgerPb.PublicKey{ + Key: prepareResponse.GetLedgerExchangeAddress(), + }, + Balance: amount, + }, + } + successSignature, err := Sign(successChannelState, privateKey) + if err != nil { + return nil, err + } + successChannelStateSigned := &ledgerPb.SignedChannelState{Channel: successChannelState, FromSignature: successSignature} + + //make signed fail channel state. + failChannelState := &ledgerPb.ChannelState{ + Id: channelId, + Sequence: 1, + From: &ledgerPb.Account{ + Address: &ledgerPb.PublicKey{ + Key: ledgerAddr, + }, + Balance: amount, + }, + To: &ledgerPb.Account{ + Address: &ledgerPb.PublicKey{ + Key: prepareResponse.GetLedgerExchangeAddress(), + }, + Balance: 0, + }, + } + failSignature, err := Sign(failChannelState, privateKey) + if err != nil { + return nil, err + } + + ctx := context.Background() + var withdrawResponse *exPb.WithdrawResponse + err = grpc.ExchangeClient(exchangeService).WithContext(ctx, + func(ctx context.Context, client exPb.ExchangeClient) error { + failChannelStateSigned := &ledgerPb.SignedChannelState{Channel: failChannelState, FromSignature: failSignature} + //Post the withdraw request. + withdrawRequest := &exPb.WithdrawRequest{ + Id: prepareResponse.GetId(), + SuccessChannelState: successChannelStateSigned, + FailureChannelState: failChannelStateSigned, + } + withdrawResponse, err = client.Withdraw(ctx, withdrawRequest) + if err != nil { + log.Error(fmt.Sprintf("Withdraw error, reasons: [%v]", err)) + return err + } + return nil + }) + if err != nil { + return nil, err + } + return withdrawResponse, nil +} + +//Get the token balance on tron blockchain +func GetTokenBalance(addr []byte, tokenId string) (int64, error) { + ctx := context.Background() + var tokenBalance int64 = 0 + err := grpc.SolidityClient(solidityService).WithContext(ctx, + func(ctx context.Context, client tronPb.WalletSolidityClient) error { + account := &corePb.Account{Address: addr} + myAccount, err := client.GetAccount(ctx, account) + if err != nil { + return err + } + tokenMap := myAccount.GetAssetV2() + if tokenMap == nil || len(tokenMap) == 0 { + return nil + } + tokenBalance = tokenMap[tokenId] + return nil + }) + if err != nil { + log.Error("wallet GetTokenBalance error: ", err) + return 0, err + } + return tokenBalance, nil +} diff --git a/core/wallet/util.go b/core/wallet/util.go new file mode 100644 index 000000000..b402dcc8e --- /dev/null +++ b/core/wallet/util.go @@ -0,0 +1,118 @@ +package wallet + +import ( + "crypto/ecdsa" + "crypto/sha256" + "encoding/hex" + "errors" + + "github.com/btcsuite/btcutil/base58" + eth "github.com/ethereum/go-ethereum/crypto" +) + +var ( + ErrDecodeLength = errors.New("base58 decode length error") + ErrDecodeCheck = errors.New("base58 check failed") + ErrEncodeLength = errors.New("base58 encode length error") +) + +const ( + AddressLength = 21 + AddressPrefix = "41" +) + +type Address [AddressLength]byte + +func PublicKeyToAddress(p ecdsa.PublicKey) (Address, error) { + addr := eth.PubkeyToAddress(p) + + addressTron := make([]byte, AddressLength) + + addressPrefix, err := FromHex(AddressPrefix) + if err != nil { + return Address{}, err + } + + addressTron = append(addressTron, addressPrefix...) + addressTron = append(addressTron, addr.Bytes()...) + + return BytesToAddress(addressTron), nil +} + +// Decode hex string as bytes +func FromHex(input string) ([]byte, error) { + if len(input) == 0 { + return nil, errors.New("empty hex string") + } + + return hex.DecodeString(input[:]) +} + +func (a *Address) Bytes() []byte { + return a[:] +} + +// Convert byte to address. +func (a *Address) SetBytes(b []byte) { + if len(b) > len(a) { + b = b[len(b)-AddressLength:] + } + copy(a[AddressLength-len(b):], b) +} + +func BytesToAddress(b []byte) Address { + var a Address + a.SetBytes(b) + return a +} + +// Decode by base58 and check. +func Decode58Check(input string) ([]byte, error) { + decodeCheck := base58.Decode(input) + if len(decodeCheck) <= 4 { + return nil, ErrDecodeLength + } + decodeData := decodeCheck[:len(decodeCheck)-4] + hash0, err := Hash(decodeData) + if err != nil { + return nil, err + } + hash1, err := Hash(hash0) + if hash1 == nil { + return nil, err + } + if hash1[0] == decodeCheck[len(decodeData)] && hash1[1] == decodeCheck[len(decodeData)+1] && + hash1[2] == decodeCheck[len(decodeData)+2] && hash1[3] == decodeCheck[len(decodeData)+3] { + return decodeData, nil + } + return nil, ErrDecodeCheck +} + +// Encode by base58 and check. +func Encode58Check(input []byte) (string, error) { + h0, err := Hash(input) + if err != nil { + return "", err + } + h1, err := Hash(h0) + if err != nil { + return "", err + } + if len(h1) < 4 { + return "", ErrEncodeLength + } + inputCheck := append(input, h1[:4]...) + + return base58.Encode(inputCheck), nil +} + +//Package goLang sha256 hash algorithm. +func Hash(s []byte) ([]byte, error) { + h := sha256.New() + _, err := h.Write(s) + if err != nil { + return nil, err + } + bs := h.Sum(nil) + return bs, nil +} diff --git a/core/wallet/wallet.go b/core/wallet/wallet.go new file mode 100644 index 000000000..6f788e347 --- /dev/null +++ b/core/wallet/wallet.go @@ -0,0 +1,204 @@ +package wallet + +import ( + "context" + "crypto/ecdsa" + "crypto/elliptic" + "encoding/hex" + "errors" + "fmt" + + config "github.com/TRON-US/go-btfs-config" + "github.com/TRON-US/go-btfs/core/escrow" + exPb "github.com/tron-us/go-btfs-common/protos/exchange" + "github.com/tron-us/go-btfs-common/utils/grpc" + + eth "github.com/ethereum/go-ethereum/crypto" + logging "github.com/ipfs/go-log" + ic "github.com/libp2p/go-libp2p-core/crypto" +) + +var log = logging.Logger("core/wallet") + +var ( + WithdrawMinAmount int64 = 1 + WithdrawMaxAmount int64 = 10000 + DepositMinAmount int64 = 1 + DepositMaxAmount int64 = 10000 + TokenId string = "1002000" + hostWallet Wallet + + escrowService string + exchangeService string + solidityService string +) + +type Wallet struct { + privKeyIC ic.PrivKey + privateKey *ecdsa.PrivateKey + tronAddress []byte // 41*** + ledgerAddress []byte // address in ledger +} + +// withdraw from ledger to tron +func (wallet *Wallet) Withdraw(amount int64, configuration *config.Config) error { + if wallet.privateKey == nil { + log.Error("wallet is not initialized") + return errors.New("wallet is not initialized") + } + + if amount < WithdrawMinAmount || amount > WithdrawMaxAmount { + return errors.New(fmt.Sprintf("withdraw amount should between %d ~ %d", WithdrawMinAmount, WithdrawMaxAmount)) + } + + ctx := context.Background() + // get ledger balance before withdraw + ledgerBalance, err := escrow.Balance(ctx, configuration) + if err != nil { + return errors.New(fmt.Sprintf("Failed to get ledger balance, reason: %v", err)) + } + log.Info(fmt.Sprintf("Get ledger account success, balance: [%d]", ledgerBalance)) + + if amount > ledgerBalance { + return errors.New(fmt.Sprintf("not enough ledger balance, current balance is %d", ledgerBalance)) + } + + // Doing withdraw request. + channelId, id, err := Withdraw(wallet.ledgerAddress, wallet.tronAddress, amount, wallet.privateKey) + if err != nil { + log.Error("Failed to Withdraw, ERR[%v]\n", err) + return err + } + + log.Info("Withdraw submitted! ChannelId: [%d], id [%d]\n", channelId, id) + return nil +} + +func (wallet *Wallet) Deposit(amount int64) error { + if wallet.privateKey == nil { + log.Error("wallet is not initialized") + return errors.New("wallet is not initialized") + } + + if amount < DepositMinAmount || amount > DepositMaxAmount { + return errors.New(fmt.Sprintf("deposit amount should between %d ~ %d", DepositMinAmount, DepositMaxAmount)) + } + + prepareResponse, err := Deposit(wallet.ledgerAddress, amount, wallet.privateKey) + if err != nil { + log.Error("Failed to Deposit, ERR[%v]\n", err) + return err + } + + log.Info("Deposit Submitted: Id [%d]\n", prepareResponse.GetId()) + return nil +} + +//GetBalance both on ledger and Tron. +func (wallet *Wallet) GetBalance(configuration *config.Config) (int64, int64, error) { + if wallet.ledgerAddress == nil || len(wallet.ledgerAddress) == 0 { + log.Error("wallet is not initialized") + return 0, 0, errors.New("wallet is not initialized") + } + + ctx := context.Background() + // get tron balance + tronBalance, err := GetTokenBalance(wallet.tronAddress, TokenId) + if err != nil { + return 0, 0, + errors.New(fmt.Sprintf("Failed to get exchange tron balance, reason: %v", err)) + } + log.Info(fmt.Sprintf("Get exchange tron account success, balance: [%d]", tronBalance)) + + // get ledger balance from escrow + ledgerBalance, err := escrow.Balance(ctx, configuration) + if err != nil { + return 0, 0, + errors.New(fmt.Sprintf("Failed to get ledger balance, reason: %v", err)) + } + log.Info(fmt.Sprintf("Get ledger account success, balance: [%d]", ledgerBalance)) + + return tronBalance, ledgerBalance, nil +} + +// activate account on tron block chain +// using wallet tronAddress 41*** +func (wallet *Wallet) ActivateAccount() error { + if wallet.tronAddress == nil { + log.Error("wallet is not initialized") + return errors.New("wallet is not initialized") + } + + ctx := context.Background() + err := grpc.ExchangeClient(exchangeService).WithContext(ctx, + func(ctx context.Context, client exPb.ExchangeClient) error { + response, err := client.ActivateAccountOnChain(ctx, + &exPb.ActivateAccountRequest{Address: wallet.tronAddress}) + if err != nil { + return err + } + log.Info("wallet activate account succeed: ", response) + return nil + }) + if err != nil { + log.Error("wallet activate account error: ", err) + return err + } + return nil +} + +func Init(configuration *config.Config) { + if configuration == nil { + log.Error("init wallet failed, input nil configuration") + return + } + + // get service name + escrowService = configuration.Services.EscrowDomain + exchangeService = configuration.Services.ExchangeDomain + solidityService = configuration.Services.SolidityDomain + + // get key + privKeyIC, err := configuration.Identity.DecodePrivateKey("") + if err != nil { + log.Error("wallet get private key failed") + return + } + // base64 key + privKeyRaw, err := privKeyIC.Raw() + if err != nil { + log.Error("wallet get private key raw failed") + return + } + // hex key + hexPrivKey := hex.EncodeToString(privKeyRaw) + log.Debug("wallet private key (hex) is:", hexPrivKey) + + // hex key to ecdsa + privateKey, err := eth.HexToECDSA(hexPrivKey) + if err != nil { + log.Error("error when convent private key to edca, ERR[%v]\n", err) + return + } + if privateKey == nil { + log.Error("wallet get private key ecdsa failed") + return + } + hostWallet.privateKey = privateKey + + // tron key 41**** + addr, err := PublicKeyToAddress(privateKey.PublicKey) + if err != nil { + log.Error("wallet get tron address failed, ERR[%v]\n ", err) + return + } + addBytes := addr.Bytes() + hostWallet.tronAddress = addBytes + hostWallet.ledgerAddress = elliptic.Marshal(elliptic.P256(), privateKey.PublicKey.X, privateKey.PublicKey.Y) + log.Info("wallet ledger address: [%s]\n", hex.EncodeToString(hostWallet.ledgerAddress)) + log.Info("wallet tron address: [%s]\n", hex.EncodeToString(hostWallet.tronAddress)) +} + +func HostWallet() *Wallet { + return &hostWallet +} diff --git a/go.mod b/go.mod index bb15b5ce1..fbdaae77a 100644 --- a/go.mod +++ b/go.mod @@ -19,15 +19,18 @@ require ( github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf github.com/blang/semver v3.5.1+incompatible github.com/bren2010/proquint v0.0.0-20160323162903-38337c27106d + github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d github.com/cenkalti/backoff/v3 v3.1.1 github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e // indirect github.com/dsnet/compress v0.0.1 // indirect github.com/dustin/go-humanize v1.0.0 github.com/elgris/jsondiff v0.0.0-20160530203242-765b5c24c302 + github.com/ethereum/go-ethereum v1.9.10 github.com/frankban/quicktest v1.4.2 // indirect github.com/fsnotify/fsnotify v1.4.7 github.com/go-ole/go-ole v1.2.4 // indirect github.com/gogo/protobuf v1.3.1 + github.com/golang/protobuf v1.3.2 github.com/golangci/golangci-lint v1.21.0 github.com/google/uuid v1.1.1 github.com/hashicorp/go-multierror v1.0.0 @@ -101,7 +104,6 @@ require ( github.com/libp2p/go-libp2p-yamux v0.2.1 github.com/libp2p/go-maddr-filter v0.0.5 github.com/libp2p/go-testutil v0.1.0 - github.com/mattn/go-runewidth v0.0.4 // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect github.com/mholt/archiver v3.1.1+incompatible github.com/mitchellh/go-homedir v1.1.0 @@ -124,7 +126,7 @@ require ( github.com/tron-us/go-btfs-common v0.2.22 github.com/tron-us/protobuf v1.3.4 github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 - github.com/tyler-smith/go-bip39 v1.0.0 + github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc github.com/whyrusleeping/go-sysinfo v0.0.0-20190219211824-4a357d4b90b1 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 diff --git a/go.sum b/go.sum index 52092573d..1bd76920e 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,19 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 h1:HD8gA2tkByhMAwYaFAX9w2l7vxvBQ5NMoxDrkhqhtn4= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= +github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc= +github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4= +github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= +github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= +github.com/Azure/go-autorest/autorest/adal v0.8.0/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc= +github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= +github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= +github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= +github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= +github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= +github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= +github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc= @@ -15,6 +28,7 @@ github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETF github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd h1:HNhzThEtZW714v8Eda8sWWRcu9WSzJC+oCyjRjvZgRA= github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd/go.mod h1:bqoB8kInrTeEtYAwaIXoSRqdwnjQmFhsfusnzyui6yY= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/OneOfOne/xxhash v1.2.5/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q= github.com/OpenPeeDeeP/depguard v1.0.1 h1:VlW4R6jmBIv3/u1JNlawEvJMM4J+dPORPaZasQee8Us= github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= @@ -53,13 +67,17 @@ github.com/TRON-US/go-unixfs v0.5.8 h1:9KlumkzOUMAnGJLIS1tBMN7r1rmk6txN8Sb4Virpi github.com/TRON-US/go-unixfs v0.5.8/go.mod h1:Lq3LNT/P7gk1IYfmwrU8XAyJg3acWUbSx8wNN85M/sw= github.com/TRON-US/interface-go-btfs-core v0.5.4 h1:rGtjXV8pRM0ap56XsI/lwB4vGUytS7mRrih0lmx+KJA= github.com/TRON-US/interface-go-btfs-core v0.5.4/go.mod h1:wZWJikVV3ShW7fClZP8/Gv8gYFg4ZowePkKBp0HY9Xc= +github.com/VictoriaMetrics/fastcache v1.5.3/go.mod h1:+jv9Ckb+za/P1ZRg/sulP5Ni1v49daAVERr0H3CuscE= github.com/Workiva/go-datastructures v1.0.50 h1:slDmfW6KCHcC7U+LP3DDBbm4fqTwZGn1beOFPfGaLvo= github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/aws/aws-sdk-go v1.25.48/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -69,12 +87,14 @@ github.com/bombsimon/wsl v1.2.5 h1:9gTOkIwVtoDZywvX802SDHokeX4kW1cKnV8ZTVAPkRs= github.com/bombsimon/wsl v1.2.5/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM= github.com/bren2010/proquint v0.0.0-20160323162903-38337c27106d h1:QgeLLoPD3kRVmeu/1al9iIpIANMi9O1zXFm8BnYGCJg= github.com/bren2010/proquint v0.0.0-20160323162903-38337c27106d/go.mod h1:Jbj8eKecMNwf0KFI75skSUZqMB4UCRcndUScVBTWyUI= +github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.0.0-20190605094302-a0d1e3e36d50 h1:4i3KsuVA0o0KoBxAC5x+MY7RbteiMK1V7gf/G08NGIQ= github.com/btcsuite/btcd v0.0.0-20190605094302-a0d1e3e36d50/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= @@ -86,12 +106,16 @@ github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH github.com/cenkalti/backoff/v3 v3.1.1 h1:UBHElAnr3ODEbpqPzX8g5sBcASjoLFtt3L/xwJ01L6E= github.com/cenkalti/backoff/v3 v3.1.1/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.0.1-0.20190104013014-3767db7a7e18/go.mod h1:HD5P3vAIAh+Y2GAxg0PrPN1P8WkepXGpjbUPDHJqqKM= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U= github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw= github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -104,6 +128,7 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0= github.com/cskr/pubsub v1.0.2/go.mod h1:/8MzYXk/NJAz782G8RPkFzXTZVu63VotefPnR9TIRis= @@ -113,6 +138,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 h1:6xT9KW8zLC5IlbaIF5Q7JNieBoACT7iW0YTxQHR0in0= github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4= +github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= github.com/dgraph-io/badger v1.6.0-rc1 h1:JphPpoBZJ3WHha133BGYlQqltSGIhV+VsEID0++nN9A= github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= @@ -123,27 +149,35 @@ github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUn github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q= github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo= github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= +github.com/elastic/gosigar v0.8.1-0.20180330100440-37f05ff46ffa/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs= github.com/elgris/jsondiff v0.0.0-20160530203242-765b5c24c302 h1:QV0ZrfBLpFc2KDk+a4LJefDczXnonRwrYrQJY/9L4dA= github.com/elgris/jsondiff v0.0.0-20160530203242-765b5c24c302/go.mod h1:qBlWZqWeVx9BjvqBsnC/8RUlAYpIFmPvgROcw0n1scE= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ethereum/go-ethereum v1.9.10 h1:jooX7tWcscpC7ytufk73t9JMCeJQ7aJF2YmZJQEuvFo= +github.com/ethereum/go-ethereum v1.9.10/go.mod h1:lXHkVo/MTvsEXfYsmNzelZ8R1e0DTvdk/wMZJIRpaRw= github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 h1:BBso6MBKW8ncyZLv37o+KNyy0HrrHgfnOaGQC2qvN+A= github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg= +github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E= +github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fomichev/secp256k1 v0.0.0-20180413221153-00116ff8c62f h1:YbIfHI+s+tauzUAdNw+lF8a9o056PoIPaLGodgh5D7g= github.com/fomichev/secp256k1 v0.0.0-20180413221153-00116ff8c62f/go.mod h1:X4BmRxczPduAy11nSLYwnR11VuvnbG7ozOTDKLHhx70= github.com/frankban/quicktest v1.4.2 h1:eV8n2LQHuA97qKj0t6+7UrHRU0Smz9G+yh87F3Z+3Uk= github.com/frankban/quicktest v1.4.2/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= @@ -209,10 +243,12 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2-0.20190517061210-b285ee9cfc6c/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM= @@ -247,6 +283,7 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -255,8 +292,11 @@ github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRid github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989 h1:giknQ4mEuDFmmHSrGcbargOuLHQGtywqo4mheITex54= +github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3 h1:JVnpOZS+qxli+rgVl98ILOXVNbW+kb5wcxeGx8ShUIw= github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE= +github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= @@ -271,6 +311,7 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -278,12 +319,14 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag= github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag= github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/ipfs/bbloom v0.0.1 h1:s7KkiBPfxCeDVo47KySjK0ACPc5GJRUxFpdyWEuDjhw= github.com/ipfs/bbloom v0.0.1/go.mod h1:oqo8CVWsJFMOZqTglBG4wydCE4IQA/G2/SEofB0rjUI= github.com/ipfs/dir-index-html v1.0.3 h1:cKdOjJBKJgewgcv97zOlqsNOle52N91d3nAkbQadnuY= @@ -398,6 +441,8 @@ github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA= +github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= @@ -415,6 +460,7 @@ github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= @@ -422,7 +468,9 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= @@ -447,6 +495,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/libp2p/go-addr-util v0.0.1 h1:TpTQm9cXVRVSKsYbgQ7GKc3KbbHVTnbostgGaDEP+88= github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ= @@ -636,14 +685,19 @@ github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwm github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb h1:RHba4YImhrUVQDHUCe2BNSOz4tVy2yGyXhvYDvxGgeE= github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= +github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= @@ -697,6 +751,8 @@ github.com/multiformats/go-multistream v0.0.4/go.mod h1:fJTiDfXJVmItycydCnNx4+wS github.com/multiformats/go-multistream v0.1.0 h1:UpO6jrsjqs46mqAK3n6wKRYFhugss9ArzbyUzU+4wkQ= github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= +github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1ORQBMvzfzBgpsctsbQikCVpvC+tX285E= @@ -704,6 +760,8 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96d github.com/nwaples/rardecode v1.0.0 h1:r7vGuS5akxOnR4JQSkko62RJ1ReCMXxQRPtxsiFMBOs= github.com/nwaples/rardecode v1.0.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -716,8 +774,10 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/pierrec/lz4 v2.2.6+incompatible h1:6aCX4/YZ9v8q69hTyiR7dNLnTA3fgtKHVVW5BCd5Znw= github.com/pierrec/lz4 v2.2.6+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -746,13 +806,19 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.0-20190519111021-9935e8e0588d h1:Z5QMcUKnQw7ouB1wDuyZM6TL/rm+brJcNk6Ai8ut3zM= github.com/prometheus/procfs v0.0.0-20190519111021-9935e8e0588d/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.6.2-0.20190402121629-4f204dcbc150/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI= +github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= +github.com/robertkrimen/otto v0.0.0-20170205013659-6a77b7cbc37d/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d h1:BzRvVq1EHuIjxpijCEKpAxzKUUMurOQ4sknehIATRh8= github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d/go.mod h1:w5+eXa0mYznDkHaMCXA4XYffjlH+cy1oyKbfzJXa2Do= github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada h1:WokF3GuxBeL+n4Lk4Fa8v9mbdjlrl7bHuneF4N1bk2I= @@ -764,6 +830,7 @@ github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e h1:MZM7FHLqUHYI0Y/mQAt github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 h1:llrF3Fs4018ePo4+G/HV/uQUqEI1HMDjCeOf2V6puPc= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= @@ -782,6 +849,7 @@ github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7A github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.0.1-0.20190317074736-539464a789e9/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= @@ -800,6 +868,9 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= +github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= +github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= @@ -810,6 +881,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e h1:T5PdfK/M1xyrHwynxMIVMWLS7f/qHwfslZphxtGnw7s= github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go.mod h1:XDKHRm5ThF8YJjx001LtgelzsoaEcvnA7lVWz9EeX3g= github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q= @@ -827,6 +899,7 @@ github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 h1:NXXyQVeRVL github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564/go.mod h1:0/YuQQF676+d4CMNclTqGUam1EDwz0B8o03K9pQqA3c= github.com/tyler-smith/go-bip39 v1.0.0 h1:FOHg9gaQLeBBRbHE/QrTLfEiBHy5pQ/yXzf9JG5pYFM= github.com/tyler-smith/go-bip39 v1.0.0/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= +github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ulikunitz/xz v0.5.6 h1:jGHAfXawEGZQ3blwU5wnWKQJvAraT7Ftq9EXjnXYgt8= @@ -837,6 +910,7 @@ github.com/ultraware/whitespace v0.0.4 h1:If7Va4cM03mpgrNH9k49/VOicWpGoG70XPBFFO github.com/ultraware/whitespace v0.0.4/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA= github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517 h1:ChMKTho2hWKpks/nD/FL2KqM1wuVt62oJeiE8+eFpGs= github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= @@ -876,6 +950,7 @@ github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c/go.mod h1: github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee h1:lYbXeSvJi5zk5GLKVuid9TVjS9a0OmLIDKTfoZBL6Ow= github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee/go.mod h1:m2aV4LZI4Aez7dP5PMyVKEHhUyEJ/RjmPEDOpDvudHg= github.com/whyrusleeping/yamux v1.1.5/go.mod h1:E8LnQQ8HKx5KD29HZFUwM1PxCOdPRzGwur1mcYhXcD8= +github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= @@ -940,6 +1015,7 @@ golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190611141213-3f473d35a33a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -968,6 +1044,7 @@ golang.org/x/sys v0.0.0-20190524152521-dbbf3f1254d4/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190526052359-791d8a0f4d09/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd h1:3x5uuvBgE6oaXJjCOvpCC1IpgJogqQ+PqGGU3ZxAgII= @@ -1026,9 +1103,13 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= +gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= +gopkg.in/olebedev/go-duktape.v3 v3.0.0-20190213234257-ec84240a7772/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -1036,6 +1117,7 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.1.0+incompatible h1:5USw7CrJBYKqjg9R7QlA6jzqZKEAtvW82aNmsxxGPxw= gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/gotestsum v0.3.4 h1:LdVJDg3RHrci4MbupUgSkwPCikz4kTzDHWtUahDAleY= gotest.tools/gotestsum v0.3.4/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From c0db0217bdedd65addd91d488012ff1f9b81c4d7 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Mon, 24 Feb 2020 12:52:30 -0800 Subject: [PATCH 02/36] add btfs wallet command --- core/commands/root.go | 1 + core/commands/wallet.go | 158 +++++++++++++++++++++++++++++++++++++ core/wallet/transaction.go | 8 +- go.mod | 2 +- go.sum | 13 ++- 5 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 core/commands/wallet.go diff --git a/core/commands/root.go b/core/commands/root.go index 469181a76..f5819caab 100644 --- a/core/commands/root.go +++ b/core/commands/root.go @@ -155,6 +155,7 @@ var rootSubcommands = map[string]*cmds.Command{ "storage": StorageCmd, "metadata": MetadataCmd, "guard": GuardCmd, + "wallet": WalletCmd, //"update": ExternalBinary(), } diff --git a/core/commands/wallet.go b/core/commands/wallet.go new file mode 100644 index 000000000..bb8eed1e8 --- /dev/null +++ b/core/commands/wallet.go @@ -0,0 +1,158 @@ +package commands + +import ( + "fmt" + "io" + "strconv" + + cmds "github.com/TRON-US/go-btfs-cmds" + "github.com/TRON-US/go-btfs/core/commands/cmdenv" + "github.com/TRON-US/go-btfs/core/wallet" +) + +var WalletCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "BTFS wallet", + ShortDescription: `'btfs wallet' is a set of commands to interact with block chain and ledger.`, + LongDescription: `'btfs wallet' is a set of commands interact with block chain and ledger to deposit, +withdraw and query balance of token used in BTFS.`, + }, + + Subcommands: map[string]*cmds.Command{ + "init": walletInitCmd, + "deposit": walletDepositCmd, + "withdraw": walletWithdrawCmd, + "balance": walletBalanceCmd, + }, +} + +var walletInitCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "Init BTFS wallet", + ShortDescription: "Init BTFS wallet.", + }, + + Arguments: []cmds.Argument{}, + Options: []cmds.Option{}, + Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { + cfg, err := cmdenv.GetConfig(env) + if err != nil { + return err + } + + wallet.Init(cfg) + return nil + }, + Encoders: cmds.EncoderMap{ + cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *MessageOutput) error { + fmt.Fprint(w, out.Message) + return nil + }), + }, + Type: MessageOutput{}, +} + +var walletDepositCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "BTFS wallet deposit", + ShortDescription: "BTFS wallet deposit from block chain to ledger.", + }, + + Arguments: []cmds.Argument{ + cmds.StringArg("amount", true, false, "amount to deposit."), + }, + Options: []cmds.Option{}, + Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { + amount, err := strconv.ParseInt(req.Arguments[0], 10, 64) + if err != nil { + return err + } + + err = wallet.HostWallet().Deposit(amount) + if err != nil { + log.Error("wallet deposit failed, err ", err) + return err + } + s := fmt.Sprintf("BTFS wallet deposit submitted. Please wait one minute for the transaction to confirm.") + return cmds.EmitOnce(res, &MessageOutput{s}) + }, + Encoders: cmds.EncoderMap{ + cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *MessageOutput) error { + fmt.Fprint(w, out.Message) + return nil + }), + }, + Type: MessageOutput{}, +} + +var walletWithdrawCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "BTFS wallet withdraw", + ShortDescription: "BTFS wallet withdraw from ledger to block chain.", + }, + + Arguments: []cmds.Argument{ + cmds.StringArg("amount", true, false, "amount to deposit."), + }, + Options: []cmds.Option{}, + Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { + cfg, err := cmdenv.GetConfig(env) + if err != nil { + return err + } + + amount, err := strconv.ParseInt(req.Arguments[0], 10, 64) + if err != nil { + return err + } + + err = wallet.HostWallet().Withdraw(amount, cfg) + if err != nil { + log.Error("wallet deposit failed, err ", err) + return err + } + + s := fmt.Sprintf("BTFS wallet withdraw submitted. Please wait one minute for the transaction to confirm.") + return cmds.EmitOnce(res, &MessageOutput{s}) + }, + Encoders: cmds.EncoderMap{ + cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *MessageOutput) error { + fmt.Fprint(w, out.Message) + return nil + }), + }, + Type: MessageOutput{}, +} + +var walletBalanceCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "BTFS wallet balance", + ShortDescription: "Query BTFS wallet balance in ledger and block chain.", + }, + + Arguments: []cmds.Argument{}, + Options: []cmds.Option{}, + Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { + cfg, err := cmdenv.GetConfig(env) + if err != nil { + return err + } + + tronBalance, lederBalance, err := wallet.HostWallet().GetBalance(cfg) + if err != nil { + log.Error("wallet deposit failed, err ", err) + return err + } + s := fmt.Sprintf("BTFS wallet tron balance '%d', ledger balance '%d'\n", tronBalance, lederBalance) + log.Info(s) + + return cmds.EmitOnce(res, &MessageOutput{s}) + }, + Encoders: cmds.EncoderMap{ + cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *MessageOutput) error { + fmt.Fprint(w, out.Message) + return nil + }), + }, + Type: MessageOutput{}, +} diff --git a/core/wallet/transaction.go b/core/wallet/transaction.go index d77b88707..7c782b3d2 100644 --- a/core/wallet/transaction.go +++ b/core/wallet/transaction.go @@ -219,10 +219,10 @@ func Withdraw(ledgerAddr, externalAddr []byte, amount int64, privateKey *ecdsa.P log.Debug(fmt.Sprintf("Prepare withdraw success, id: [%d]", prepareResponse.GetId())) channelCommit := &ledgerPb.ChannelCommit{ - Payer: &ledgerPb.PublicKey{Key: ledgerAddr}, - Receiver: &ledgerPb.PublicKey{Key: prepareResponse.GetLedgerExchangeAddress()}, - Amount: amount, - PayerId: time.Now().UnixNano() + prepareResponse.GetId(), + Payer: &ledgerPb.PublicKey{Key: ledgerAddr}, + Recipient: &ledgerPb.PublicKey{Key: prepareResponse.GetLedgerExchangeAddress()}, + Amount: amount, + PayerId: time.Now().UnixNano() + prepareResponse.GetId(), } //Sign channel commit. signature, err := Sign(channelCommit, privateKey) diff --git a/go.mod b/go.mod index fbdaae77a..1ca452d64 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/TRON-US/go-btfs-api v0.1.0 github.com/TRON-US/go-btfs-chunker v0.2.7 github.com/TRON-US/go-btfs-cmds v0.1.6 - github.com/TRON-US/go-btfs-config v0.4.5 + github.com/TRON-US/go-btfs-config v0.4.6 github.com/TRON-US/go-btfs-files v0.1.5 github.com/TRON-US/go-eccrypto v0.0.1 github.com/TRON-US/go-mfs v0.2.2 diff --git a/go.sum b/go.sum index 1bd76920e..21728b0ec 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/TRON-US/go-btfs-chunker v0.2.7 h1:eLIZjETFbCsQ2lY9gw97x8MHZJkfOUfsZ05 github.com/TRON-US/go-btfs-chunker v0.2.7/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= github.com/TRON-US/go-btfs-cmds v0.1.6 h1:r1JCcAfWxGHpFxZpmlQN3NTEqbN9BRmX4ximfmBh2ok= github.com/TRON-US/go-btfs-cmds v0.1.6/go.mod h1:rtki4vmPzq7qmjdzThJELFpSpxTiORoXreHlExdI6eg= -github.com/TRON-US/go-btfs-config v0.4.5 h1:xgFwdxOvPSWgNRPIvx8PgXgT3SSlH0I72UuI6LTmQ4A= -github.com/TRON-US/go-btfs-config v0.4.5/go.mod h1:045+FmBpTIWNy34ISzjtPaEf6afBq6wVQtviNmAnF5g= +github.com/TRON-US/go-btfs-config v0.4.6 h1:g90OJ6HEMQDw++dXxS1KWzg+ihImPUAWazWA+Tgh+jY= +github.com/TRON-US/go-btfs-config v0.4.6/go.mod h1:045+FmBpTIWNy34ISzjtPaEf6afBq6wVQtviNmAnF5g= github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0= github.com/TRON-US/go-btfs-files v0.1.5 h1:MH+kqwVPG+EzMeQ+0XygPmaFrwXnN1j3rtgHUbvw9Uk= github.com/TRON-US/go-btfs-files v0.1.5/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE= @@ -127,7 +127,9 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0= @@ -248,6 +250,7 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= @@ -817,7 +820,9 @@ github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9Ac github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= +github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d h1:BzRvVq1EHuIjxpijCEKpAxzKUUMurOQ4sknehIATRh8= github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d/go.mod h1:w5+eXa0mYznDkHaMCXA4XYffjlH+cy1oyKbfzJXa2Do= @@ -830,6 +835,7 @@ github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e h1:MZM7FHLqUHYI0Y/mQAt github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 h1:llrF3Fs4018ePo4+G/HV/uQUqEI1HMDjCeOf2V6puPc= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -881,6 +887,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e h1:T5PdfK/M1xyrHwynxMIVMWLS7f/qHwfslZphxtGnw7s= github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go.mod h1:XDKHRm5ThF8YJjx001LtgelzsoaEcvnA7lVWz9EeX3g= @@ -899,6 +906,7 @@ github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 h1:NXXyQVeRVL github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564/go.mod h1:0/YuQQF676+d4CMNclTqGUam1EDwz0B8o03K9pQqA3c= github.com/tyler-smith/go-bip39 v1.0.0 h1:FOHg9gaQLeBBRbHE/QrTLfEiBHy5pQ/yXzf9JG5pYFM= github.com/tyler-smith/go-bip39 v1.0.0/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= +github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef h1:wHSqTBrZW24CsNJDfeh9Ex6Pm0Rcpc7qrgKBiL44vF4= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= @@ -910,6 +918,7 @@ github.com/ultraware/whitespace v0.0.4 h1:If7Va4cM03mpgrNH9k49/VOicWpGoG70XPBFFO github.com/ultraware/whitespace v0.0.4/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA= github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517 h1:ChMKTho2hWKpks/nD/FL2KqM1wuVt62oJeiE8+eFpGs= github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM= From fee0b572d241e1e6a20ffef2c0c068fd820944b5 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Thu, 27 Feb 2020 15:11:49 -0800 Subject: [PATCH 03/36] update code --- core/commands/wallet.go | 18 ++++--- core/wallet/wallet.go | 102 +++++++++++++++++++++++++++------------- go.mod | 4 +- go.sum | 5 +- 4 files changed, 86 insertions(+), 43 deletions(-) diff --git a/core/commands/wallet.go b/core/commands/wallet.go index bb8eed1e8..0e849c001 100644 --- a/core/commands/wallet.go +++ b/core/commands/wallet.go @@ -37,6 +37,7 @@ var walletInitCmd = &cmds.Command{ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { cfg, err := cmdenv.GetConfig(env) if err != nil { + fmt.Println("get config failed") return err } @@ -63,14 +64,19 @@ var walletDepositCmd = &cmds.Command{ }, Options: []cmds.Option{}, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { + cfg, err := cmdenv.GetConfig(env) + if err != nil { + return err + } + amount, err := strconv.ParseInt(req.Arguments[0], 10, 64) if err != nil { return err } - err = wallet.HostWallet().Deposit(amount) + err = wallet.WalletDeposit(cfg, amount) if err != nil { - log.Error("wallet deposit failed, err ", err) + log.Error("wallet deposit failed, ERR: ", err) return err } s := fmt.Sprintf("BTFS wallet deposit submitted. Please wait one minute for the transaction to confirm.") @@ -106,9 +112,9 @@ var walletWithdrawCmd = &cmds.Command{ return err } - err = wallet.HostWallet().Withdraw(amount, cfg) + err = wallet.WalletWithdraw(cfg, amount) if err != nil { - log.Error("wallet deposit failed, err ", err) + log.Error("wallet withdraw failed, ERR: ", err) return err } @@ -138,9 +144,9 @@ var walletBalanceCmd = &cmds.Command{ return err } - tronBalance, lederBalance, err := wallet.HostWallet().GetBalance(cfg) + tronBalance, lederBalance, err := wallet.GetBalance(cfg) if err != nil { - log.Error("wallet deposit failed, err ", err) + log.Error("wallet get balance failed, ERR: ", err) return err } s := fmt.Sprintf("BTFS wallet tron balance '%d', ledger balance '%d'\n", tronBalance, lederBalance) diff --git a/core/wallet/wallet.go b/core/wallet/wallet.go index 6f788e347..475741ae0 100644 --- a/core/wallet/wallet.go +++ b/core/wallet/wallet.go @@ -3,10 +3,10 @@ package wallet import ( "context" "crypto/ecdsa" - "crypto/elliptic" "encoding/hex" "errors" "fmt" + "strings" config "github.com/TRON-US/go-btfs-config" "github.com/TRON-US/go-btfs/core/escrow" @@ -22,10 +22,11 @@ var log = logging.Logger("core/wallet") var ( WithdrawMinAmount int64 = 1 - WithdrawMaxAmount int64 = 10000 + WithdrawMaxAmount int64 = 1000000000000 DepositMinAmount int64 = 1 - DepositMaxAmount int64 = 10000 + DepositMaxAmount int64 = 1000000000000 TokenId string = "1002000" + TokenIdDev string = "1002508" hostWallet Wallet escrowService string @@ -41,8 +42,13 @@ type Wallet struct { } // withdraw from ledger to tron -func (wallet *Wallet) Withdraw(amount int64, configuration *config.Config) error { - if wallet.privateKey == nil { +func WalletWithdraw(configuration *config.Config, amount int64) error { + err := Init(configuration) + if err != nil { + return err + } + + if hostWallet.privateKey == nil { log.Error("wallet is not initialized") return errors.New("wallet is not initialized") } @@ -64,18 +70,23 @@ func (wallet *Wallet) Withdraw(amount int64, configuration *config.Config) error } // Doing withdraw request. - channelId, id, err := Withdraw(wallet.ledgerAddress, wallet.tronAddress, amount, wallet.privateKey) + channelId, id, err := Withdraw(hostWallet.ledgerAddress, hostWallet.tronAddress, amount, hostWallet.privateKey) if err != nil { log.Error("Failed to Withdraw, ERR[%v]\n", err) return err } - log.Info("Withdraw submitted! ChannelId: [%d], id [%d]\n", channelId, id) + fmt.Println(fmt.Sprintf("Withdraw submitted! ChannelId: [%d], id [%d]\n", channelId, id)) return nil } -func (wallet *Wallet) Deposit(amount int64) error { - if wallet.privateKey == nil { +func WalletDeposit(configuration *config.Config, amount int64) error { + err := Init(configuration) + if err != nil { + return err + } + + if hostWallet.privateKey == nil { log.Error("wallet is not initialized") return errors.New("wallet is not initialized") } @@ -84,30 +95,43 @@ func (wallet *Wallet) Deposit(amount int64) error { return errors.New(fmt.Sprintf("deposit amount should between %d ~ %d", DepositMinAmount, DepositMaxAmount)) } - prepareResponse, err := Deposit(wallet.ledgerAddress, amount, wallet.privateKey) + prepareResponse, err := Deposit(hostWallet.ledgerAddress, amount, hostWallet.privateKey) if err != nil { log.Error("Failed to Deposit, ERR[%v]\n", err) return err } - log.Info("Deposit Submitted: Id [%d]\n", prepareResponse.GetId()) + fmt.Println(fmt.Sprintf("Deposit Submitted: Id [%d]\n", prepareResponse.GetId())) return nil } //GetBalance both on ledger and Tron. -func (wallet *Wallet) GetBalance(configuration *config.Config) (int64, int64, error) { - if wallet.ledgerAddress == nil || len(wallet.ledgerAddress) == 0 { +func GetBalance(configuration *config.Config) (int64, int64, error) { + err := Init(configuration) + if err != nil { + return 0, 0, err + } + + if hostWallet.privateKey == nil { log.Error("wallet is not initialized") return 0, 0, errors.New("wallet is not initialized") } ctx := context.Background() // get tron balance - tronBalance, err := GetTokenBalance(wallet.tronAddress, TokenId) + tokenId := TokenId + if strings.Contains(configuration.Services.EscrowDomain, "dev") || + strings.Contains(configuration.Services.EscrowDomain, "staging") { + tokenId = TokenIdDev + } + fmt.Println("token id:", tokenId) + + tronBalance, err := GetTokenBalance(hostWallet.tronAddress, tokenId) if err != nil { return 0, 0, errors.New(fmt.Sprintf("Failed to get exchange tron balance, reason: %v", err)) } + log.Info(fmt.Sprintf("Get exchange tron account success, balance: [%d]", tronBalance)) // get ledger balance from escrow @@ -116,6 +140,7 @@ func (wallet *Wallet) GetBalance(configuration *config.Config) (int64, int64, er return 0, 0, errors.New(fmt.Sprintf("Failed to get ledger balance, reason: %v", err)) } + log.Info(fmt.Sprintf("Get ledger account success, balance: [%d]", ledgerBalance)) return tronBalance, ledgerBalance, nil @@ -123,21 +148,26 @@ func (wallet *Wallet) GetBalance(configuration *config.Config) (int64, int64, er // activate account on tron block chain // using wallet tronAddress 41*** -func (wallet *Wallet) ActivateAccount() error { - if wallet.tronAddress == nil { +func ActivateAccount(configuration *config.Config) error { + err := Init(configuration) + if err != nil { + return err + } + + if hostWallet.tronAddress == nil { log.Error("wallet is not initialized") return errors.New("wallet is not initialized") } ctx := context.Background() - err := grpc.ExchangeClient(exchangeService).WithContext(ctx, + err = grpc.ExchangeClient(exchangeService).WithContext(ctx, func(ctx context.Context, client exPb.ExchangeClient) error { response, err := client.ActivateAccountOnChain(ctx, - &exPb.ActivateAccountRequest{Address: wallet.tronAddress}) + &exPb.ActivateAccountRequest{Address: hostWallet.tronAddress}) if err != nil { return err } - log.Info("wallet activate account succeed: ", response) + fmt.Println("wallet activate account succeed: ", response) return nil }) if err != nil { @@ -147,10 +177,11 @@ func (wallet *Wallet) ActivateAccount() error { return nil } -func Init(configuration *config.Config) { +func Init(configuration *config.Config) error { if configuration == nil { + fmt.Println("Init wallet, configuration is nil") log.Error("init wallet failed, input nil configuration") - return + return errors.New("init wallet failed") } // get service name @@ -162,27 +193,28 @@ func Init(configuration *config.Config) { privKeyIC, err := configuration.Identity.DecodePrivateKey("") if err != nil { log.Error("wallet get private key failed") - return + return err } // base64 key privKeyRaw, err := privKeyIC.Raw() if err != nil { log.Error("wallet get private key raw failed") - return + return err } // hex key hexPrivKey := hex.EncodeToString(privKeyRaw) log.Debug("wallet private key (hex) is:", hexPrivKey) + fmt.Println("wallet private key (hex) is:", hexPrivKey) // hex key to ecdsa privateKey, err := eth.HexToECDSA(hexPrivKey) if err != nil { log.Error("error when convent private key to edca, ERR[%v]\n", err) - return + return err } if privateKey == nil { log.Error("wallet get private key ecdsa failed") - return + return err } hostWallet.privateKey = privateKey @@ -190,15 +222,21 @@ func Init(configuration *config.Config) { addr, err := PublicKeyToAddress(privateKey.PublicKey) if err != nil { log.Error("wallet get tron address failed, ERR[%v]\n ", err) - return + return err } addBytes := addr.Bytes() hostWallet.tronAddress = addBytes - hostWallet.ledgerAddress = elliptic.Marshal(elliptic.P256(), privateKey.PublicKey.X, privateKey.PublicKey.Y) - log.Info("wallet ledger address: [%s]\n", hex.EncodeToString(hostWallet.ledgerAddress)) - log.Info("wallet tron address: [%s]\n", hex.EncodeToString(hostWallet.tronAddress)) -} -func HostWallet() *Wallet { - return &hostWallet + ledgerAddress, err := ic.RawFull(privKeyIC.GetPublic()) + if err != nil { + fmt.Println("get ledger address failed, ERR: \n", err) + return err + } + + hostWallet.ledgerAddress = ledgerAddress + //elliptic.Marshal(elliptic.P256(), privateKey.PublicKey.X, privateKey.PublicKey.Y) + fmt.Println("wallet ledger address:\n", hex.EncodeToString(hostWallet.ledgerAddress)) + fmt.Println("wallet tron address:\n", hex.EncodeToString(hostWallet.tronAddress)) + + return nil } diff --git a/go.mod b/go.mod index 1ca452d64..f80bca885 100644 --- a/go.mod +++ b/go.mod @@ -122,8 +122,8 @@ require ( github.com/prometheus/procfs v0.0.0-20190519111021-9935e8e0588d // indirect github.com/shirou/gopsutil v2.19.11+incompatible github.com/stretchr/testify v1.4.0 - github.com/syndtr/goleveldb v1.0.0 - github.com/tron-us/go-btfs-common v0.2.22 + github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d + github.com/tron-us/go-btfs-common v0.2.25 github.com/tron-us/protobuf v1.3.4 github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef diff --git a/go.sum b/go.sum index 21728b0ec..49db84d9c 100644 --- a/go.sum +++ b/go.sum @@ -894,10 +894,9 @@ github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go. github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q= github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tron-us/go-btfs-common v0.2.11 h1:hxc7oUQHPViKzdaTZLHuS2vyYU1e6/IToZI7UY1p2Tk= github.com/tron-us/go-btfs-common v0.2.11/go.mod h1:9ND33JahGMg52sCC2/gO5DakLsd1Pg2lVe2CihW7lBE= -github.com/tron-us/go-btfs-common v0.2.22 h1:lTuY2wABFg2mG50s2EbNlKdA9jd4BrxbnHFESHt6NOs= -github.com/tron-us/go-btfs-common v0.2.22/go.mod h1:FbYoo6ZrtnJH3TKdyJTGQrUP2rbwNVATQpxplwaYQ/c= +github.com/tron-us/go-btfs-common v0.2.25 h1:p3x/fEBnNn46o3wTOHiUi0j524w3WckOU1WOy0nC6jY= +github.com/tron-us/go-btfs-common v0.2.25/go.mod h1:FbYoo6ZrtnJH3TKdyJTGQrUP2rbwNVATQpxplwaYQ/c= github.com/tron-us/go-common/v2 v2.0.5 h1:LiGEmOd0FVVRisFyg3AJWDWMXlM537M3JZ+gh75sBlw= github.com/tron-us/go-common/v2 v2.0.5/go.mod h1:GiKX9noBLHotkZAU+7ET4h7N0DYWnm3OcGHOFJg1Q68= github.com/tron-us/protobuf v1.3.4 h1:oqokl6jMAfe1fb/B6t1UMllbw/KtfdJcCn8plxPkHM8= From 170d22494a0561e71c79a27e847edc5f0ceac646 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Fri, 28 Feb 2020 11:52:22 -0800 Subject: [PATCH 04/36] update go-btfs-config version --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f80bca885..bc25d23de 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/TRON-US/go-btfs-api v0.1.0 github.com/TRON-US/go-btfs-chunker v0.2.7 github.com/TRON-US/go-btfs-cmds v0.1.6 - github.com/TRON-US/go-btfs-config v0.4.6 + github.com/TRON-US/go-btfs-config v0.4.7 github.com/TRON-US/go-btfs-files v0.1.5 github.com/TRON-US/go-eccrypto v0.0.1 github.com/TRON-US/go-mfs v0.2.2 diff --git a/go.sum b/go.sum index 49db84d9c..9c902b6dc 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,8 @@ github.com/TRON-US/go-btfs-cmds v0.1.6 h1:r1JCcAfWxGHpFxZpmlQN3NTEqbN9BRmX4ximfm github.com/TRON-US/go-btfs-cmds v0.1.6/go.mod h1:rtki4vmPzq7qmjdzThJELFpSpxTiORoXreHlExdI6eg= github.com/TRON-US/go-btfs-config v0.4.6 h1:g90OJ6HEMQDw++dXxS1KWzg+ihImPUAWazWA+Tgh+jY= github.com/TRON-US/go-btfs-config v0.4.6/go.mod h1:045+FmBpTIWNy34ISzjtPaEf6afBq6wVQtviNmAnF5g= +github.com/TRON-US/go-btfs-config v0.4.7 h1:ZK/eRkVQWqSIumzHcJ6kb2OKJwzZfhh3OINQjEjK8Fc= +github.com/TRON-US/go-btfs-config v0.4.7/go.mod h1:045+FmBpTIWNy34ISzjtPaEf6afBq6wVQtviNmAnF5g= github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0= github.com/TRON-US/go-btfs-files v0.1.5 h1:MH+kqwVPG+EzMeQ+0XygPmaFrwXnN1j3rtgHUbvw9Uk= github.com/TRON-US/go-btfs-files v0.1.5/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE= From d01cb81b5f63f054ceefa46d4c2c4ce2954bdecc Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Fri, 28 Feb 2020 12:46:41 -0800 Subject: [PATCH 05/36] remove private key print --- core/wallet/wallet.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/wallet/wallet.go b/core/wallet/wallet.go index 475741ae0..8dd8c216b 100644 --- a/core/wallet/wallet.go +++ b/core/wallet/wallet.go @@ -203,9 +203,6 @@ func Init(configuration *config.Config) error { } // hex key hexPrivKey := hex.EncodeToString(privKeyRaw) - log.Debug("wallet private key (hex) is:", hexPrivKey) - fmt.Println("wallet private key (hex) is:", hexPrivKey) - // hex key to ecdsa privateKey, err := eth.HexToECDSA(hexPrivKey) if err != nil { From 9776b5b5b52860088083f4db982d36e572b8f96e Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Fri, 28 Feb 2020 15:51:36 -0800 Subject: [PATCH 06/36] fix unit test --- core/commands/commands_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/commands/commands_test.go b/core/commands/commands_test.go index 2323411bb..d22ced019 100644 --- a/core/commands/commands_test.go +++ b/core/commands/commands_test.go @@ -252,6 +252,11 @@ func TestCommands(t *testing.T) { "/guard", "/guard/test", "/guard/test/send-challenges", + "/wallet", + "/wallet/init", + "/wallet/balance", + "/wallet/withdraw", + "/wallet/deposit", } cmdSet := make(map[string]struct{}) From 71adaf24afe45b3d2d1fd2a39db2fd0fb61cc8b1 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Mon, 2 Mar 2020 17:46:53 -0800 Subject: [PATCH 07/36] BTFS-1586 --- core/coreapi/unixfs.go | 28 ++++-------- core/coreunix/add.go | 9 ++++ core/coreunix/reed_solomon_add.go | 72 ++++++++++++++++++++++++++----- go.mod | 6 +++ 4 files changed, 86 insertions(+), 29 deletions(-) diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index ff2a925ea..58f664731 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -192,31 +192,21 @@ func (api *UnixfsAPI) Add(ctx context.Context, node files.Node, opts ...options. // if chunker is reed-solomon and the given `node` is directory, // create ReedSolomonAdder. Otherwise use Adder. var nd ipld.Node - _, ok := node.(files.Directory) + dir, ok := node.(files.Directory) if ok && chunker.IsReedSolomon(settings.Chunker) { rsfileAdder, err := coreunix.NewReedSolomonAdder(fileAdder) if err != nil { return nil, err } rsfileAdder.IsDir = true - - if api.nd.IsDaemon { - dir, ok := node.(files.Directory) - if !ok { - return nil, errors.New("expected files.Directory type") - } - it := dir.Entries() - it.SetReedSolomon() - path, err := it.AbsRootPath() - if err != nil { - return nil, err - } - if path != "" { - node, err = newSerialFileNode(path, false) - if err != nil { - return nil, err - } - } + if files.IsMultiPartDirectory(dir) { + rsfileAdder.FileType = coreunix.MultipartFile + } else if files.IsMapDirectory(dir) { + rsfileAdder.FileType = coreunix.SliceFile + } else if files.IsSerialFileDirectory(dir){ + rsfileAdder.FileType = coreunix.SerialFile + } else { + return nil, fmt.Errorf("unexpected files.Directory type [%T]", dir) } nd, err = rsfileAdder.AddAllAndPin(node) } else { diff --git a/core/coreunix/add.go b/core/coreunix/add.go index ef6434b02..0075dbbf6 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -668,3 +668,12 @@ type progressReader2 struct { func (i *progressReader2) Read(p []byte) (int, error) { return i.progressReader.Read(p) } + +type progressReader3 struct { + *progressReader + files.Node +} + +func (i *progressReader3) Read(p []byte) (int, error) { + return i.progressReader.Read(p) +} diff --git a/core/coreunix/reed_solomon_add.go b/core/coreunix/reed_solomon_add.go index dc520c228..900f73563 100644 --- a/core/coreunix/reed_solomon_add.go +++ b/core/coreunix/reed_solomon_add.go @@ -1,8 +1,10 @@ package coreunix import ( + "bytes" "errors" "io" + "io/ioutil" gopath "path" "container/list" @@ -14,8 +16,15 @@ import ( dag "github.com/ipfs/go-merkledag" ) +const ( + SerialFile = iota + 1 + MultipartFile + SliceFile +) + type ReedSolomonAdder struct { Adder + FileType int InfileReaders []io.Reader IsDir bool CurrentOffset uint64 @@ -78,7 +87,12 @@ func (rsadder *ReedSolomonAdder) AddAllAndPin(file files.Node) (ipld.Node, error } else { var reader io.Reader = io.MultiReader(rsadder.InfileReaders...) if rsadder.Progress { - reader = &progressReader{file: reader, path: "", out: rsadder.Out} + rdr := &progressReader{file: reader, path: "", out: rsadder.Out} + if file, ok := file.(files.Node); ok { + reader = &progressReader3{rdr, file} + } else { + reader = rdr + } } // Create a DAG with the above directory tree as metadata and @@ -113,7 +127,6 @@ func (rsadder *ReedSolomonAdder) addFileNode(path string, file files.Node, fList defer func() { fList.PushFront(file) }() - err := rsadder.maybePauseForGC() if err != nil { return nil, err @@ -162,7 +175,12 @@ func (rsadder *ReedSolomonAdder) addDir(path string, dir files.Directory, fList size += uint64(child.NodeSize()) } node.Siz = size - + if toplevel && rsadder.FileType == MultipartFile { + err := dir.SetSize(int64(size)) + if err != nil { + return nil, err + } + } return node, it.Err() } @@ -179,23 +197,57 @@ func (rsadder *ReedSolomonAdder) addSymlink(path string, l *files.Symlink) (uio. }, nil } +func getReader(r io.Reader) (io.Reader, int64, error) { + buf, err := ioutil.ReadAll(r) + if err != nil { + return nil, 0, err + } + + fSize := int64(len(buf)) + r = bytes.NewReader(buf) + return r, fSize, nil +} + func (rsadder *ReedSolomonAdder) addFile(path string, file files.File) (uio.Node, error) { _, dstName := gopath.Split(path) + var ( + reader io.Reader = file + fSize int64 + err error + ) - var reader io.Reader = file - rsadder.InfileReaders = append(rsadder.InfileReaders, reader) - size, err := file.Size() - if err != nil { - return nil, err + switch rsadder.FileType { + case MultipartFile: + rf, ok := file.(*files.ReaderFile) + if !ok { + return nil, errors.New("expected multipartFile file type") + } + + reader, fSize, err = getReader(rf.Reader()) + if err != nil { + return nil, err + } + case SerialFile: + fSize, err = file.Size() + if err != nil { + return nil, err + } + case SliceFile: + return nil, errors.New("SliceFile type is not supported") + default: + return nil, errors.New("unsupported file type") } + + rsadder.InfileReaders = append(rsadder.InfileReaders, reader) currentOffset := rsadder.CurrentOffset - rsadder.CurrentOffset += uint64(size) + rsadder.CurrentOffset += uint64(fSize) + node := &uio.FileNode{ BaseNode: uio.BaseNode{ NodeType: uio.FileNodeType, NodePath: path, NodeName: dstName, - Siz: uint64(size), + Siz: uint64(fSize), StartOffset: currentOffset, }, // Kept the following line for the same reason as DirNode. diff --git a/go.mod b/go.mod index bc25d23de..05d56bfdc 100644 --- a/go.mod +++ b/go.mod @@ -152,3 +152,9 @@ replace github.com/ipfs/go-ipld-format => github.com/TRON-US/go-ipld-format v0.1 replace github.com/ipfs/go-cid => github.com/TRON-US/go-cid v0.1.0 replace github.com/libp2p/go-libp2p-core => github.com/TRON-US/go-libp2p-core v0.4.1 + +replace github.com/TRON-US/go-btfs-files => ../go-btfs-files + +replace github.com/TRON-US/go-unixfs => ../go-unixfs + +replace github.com/TRON-US/go-btfs-chunker => ../go-btfs-chunker From 6737fdd1c18ce5f63b6d9779d44038b160aa1459 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Mon, 2 Mar 2020 17:49:19 -0800 Subject: [PATCH 08/36] BTFS-1586 --- core/coreapi/unixfs.go | 6 +++--- core/coreunix/reed_solomon_add.go | 4 ++-- go.sum | 19 ++----------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index 58f664731..7800e4aac 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -199,11 +199,11 @@ func (api *UnixfsAPI) Add(ctx context.Context, node files.Node, opts ...options. return nil, err } rsfileAdder.IsDir = true - if files.IsMultiPartDirectory(dir) { - rsfileAdder.FileType = coreunix.MultipartFile + if files.IsMultiPartDirectory(dir) { + rsfileAdder.FileType = coreunix.MultipartFile } else if files.IsMapDirectory(dir) { rsfileAdder.FileType = coreunix.SliceFile - } else if files.IsSerialFileDirectory(dir){ + } else if files.IsSerialFileDirectory(dir) { rsfileAdder.FileType = coreunix.SerialFile } else { return nil, fmt.Errorf("unexpected files.Directory type [%T]", dir) diff --git a/core/coreunix/reed_solomon_add.go b/core/coreunix/reed_solomon_add.go index 900f73563..63b852902 100644 --- a/core/coreunix/reed_solomon_add.go +++ b/core/coreunix/reed_solomon_add.go @@ -212,8 +212,8 @@ func (rsadder *ReedSolomonAdder) addFile(path string, file files.File) (uio.Node _, dstName := gopath.Split(path) var ( reader io.Reader = file - fSize int64 - err error + fSize int64 + err error ) switch rsadder.FileType { diff --git a/go.sum b/go.sum index 9c902b6dc..17b2d6868 100644 --- a/go.sum +++ b/go.sum @@ -38,21 +38,10 @@ github.com/Stebalien/go-bitfield v0.0.1 h1:X3kbSSPUaJK60wV2hjOPZwmpljr6VGCqdq4cB github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s= github.com/TRON-US/go-btfs-api v0.1.0 h1:YRS/RF2lSWlUJE2CaCnfpNsUu/OEpic1AXnGBX/PXQc= github.com/TRON-US/go-btfs-api v0.1.0/go.mod h1:XoXb4w+3ZF665lSdbhCDnINII2lEdwi4pAItlpdZVHI= -github.com/TRON-US/go-btfs-chunker v0.2.2/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= -github.com/TRON-US/go-btfs-chunker v0.2.3/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= -github.com/TRON-US/go-btfs-chunker v0.2.4/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= -github.com/TRON-US/go-btfs-chunker v0.2.6/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= -github.com/TRON-US/go-btfs-chunker v0.2.7 h1:eLIZjETFbCsQ2lY9gw97x8MHZJkfOUfsZ05uxfKZF6Y= -github.com/TRON-US/go-btfs-chunker v0.2.7/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= github.com/TRON-US/go-btfs-cmds v0.1.6 h1:r1JCcAfWxGHpFxZpmlQN3NTEqbN9BRmX4ximfmBh2ok= github.com/TRON-US/go-btfs-cmds v0.1.6/go.mod h1:rtki4vmPzq7qmjdzThJELFpSpxTiORoXreHlExdI6eg= -github.com/TRON-US/go-btfs-config v0.4.6 h1:g90OJ6HEMQDw++dXxS1KWzg+ihImPUAWazWA+Tgh+jY= -github.com/TRON-US/go-btfs-config v0.4.6/go.mod h1:045+FmBpTIWNy34ISzjtPaEf6afBq6wVQtviNmAnF5g= github.com/TRON-US/go-btfs-config v0.4.7 h1:ZK/eRkVQWqSIumzHcJ6kb2OKJwzZfhh3OINQjEjK8Fc= github.com/TRON-US/go-btfs-config v0.4.7/go.mod h1:045+FmBpTIWNy34ISzjtPaEf6afBq6wVQtviNmAnF5g= -github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0= -github.com/TRON-US/go-btfs-files v0.1.5 h1:MH+kqwVPG+EzMeQ+0XygPmaFrwXnN1j3rtgHUbvw9Uk= -github.com/TRON-US/go-btfs-files v0.1.5/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE= github.com/TRON-US/go-cid v0.1.0 h1:54gblgLGL2S3mJX3m3GyTdKVqJVUcG+kCkCqWjZvrdM= github.com/TRON-US/go-cid v0.1.0/go.mod h1:Rq2SnJvLEaPmL3B1JUHtVQ0b/GtkDtpY9BxDR537NPU= github.com/TRON-US/go-eccrypto v0.0.1 h1:+/5Uid61UGysbxv6Cv6gx4ru1gEiJOlir/P7ElAe7A0= @@ -63,10 +52,6 @@ github.com/TRON-US/go-libp2p-core v0.4.1 h1:vOTph4f42uxr2r2oAyCogIUxsHl2b5vWen2f github.com/TRON-US/go-libp2p-core v0.4.1/go.mod h1:B9V1MQtCLGp+jUXNdKJzNllFSsVSMuex1+5/fyWgYl0= github.com/TRON-US/go-mfs v0.2.2 h1:EUlDvvSo8HKso4oy05Ce8ZG6arASAdirV2BzAYfKTsM= github.com/TRON-US/go-mfs v0.2.2/go.mod h1:NduHl3CtI8J81aY4aV/Si/9XZbZ/+hHzPZUHC9Ho3WQ= -github.com/TRON-US/go-unixfs v0.4.4/go.mod h1:VBRlISp23R6JoJQ2t+O/VkIswnPo9PBVCh5blMpN0GI= -github.com/TRON-US/go-unixfs v0.4.12/go.mod h1:0Jv/z5OvpB4JpjJcUFB9turYohcoqjF/tmczQX9eeJ4= -github.com/TRON-US/go-unixfs v0.5.8 h1:9KlumkzOUMAnGJLIS1tBMN7r1rmk6txN8Sb4VirpiW4= -github.com/TRON-US/go-unixfs v0.5.8/go.mod h1:Lq3LNT/P7gk1IYfmwrU8XAyJg3acWUbSx8wNN85M/sw= github.com/TRON-US/interface-go-btfs-core v0.5.4 h1:rGtjXV8pRM0ap56XsI/lwB4vGUytS7mRrih0lmx+KJA= github.com/TRON-US/interface-go-btfs-core v0.5.4/go.mod h1:wZWJikVV3ShW7fClZP8/Gv8gYFg4ZowePkKBp0HY9Xc= github.com/VictoriaMetrics/fastcache v1.5.3/go.mod h1:+jv9Ckb+za/P1ZRg/sulP5Ni1v49daAVERr0H3CuscE= @@ -288,6 +273,7 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= @@ -905,8 +891,6 @@ github.com/tron-us/protobuf v1.3.4 h1:oqokl6jMAfe1fb/B6t1UMllbw/KtfdJcCn8plxPkHM github.com/tron-us/protobuf v1.3.4/go.mod h1:INMJF54ZV6c8ZMc3imHsMl1kqIpe4VnbCUK4zYcVHqE= github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 h1:NXXyQVeRVLK8Xu27/hkkjwVOZLk5v4ZBEvvMtqMqznM= github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564/go.mod h1:0/YuQQF676+d4CMNclTqGUam1EDwz0B8o03K9pQqA3c= -github.com/tyler-smith/go-bip39 v1.0.0 h1:FOHg9gaQLeBBRbHE/QrTLfEiBHy5pQ/yXzf9JG5pYFM= -github.com/tyler-smith/go-bip39 v1.0.0/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef h1:wHSqTBrZW24CsNJDfeh9Ex6Pm0Rcpc7qrgKBiL44vF4= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= @@ -1127,6 +1111,7 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.1.0+incompatible h1:5USw7CrJBYKqjg9R7QlA6jzqZKEAtvW82aNmsxxGPxw= gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/gotestsum v0.3.4 h1:LdVJDg3RHrci4MbupUgSkwPCikz4kTzDHWtUahDAleY= gotest.tools/gotestsum v0.3.4/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY= From e85f7f256f97642aae769552ccc10901aad02147 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Tue, 3 Mar 2020 17:23:42 -0800 Subject: [PATCH 09/36] BTFS-1586 --- go.mod | 12 +++--------- go.sum | 12 ++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 05d56bfdc..2fc21846b 100644 --- a/go.mod +++ b/go.mod @@ -7,13 +7,13 @@ require ( github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect github.com/TRON-US/go-btfs-api v0.1.0 - github.com/TRON-US/go-btfs-chunker v0.2.7 + github.com/TRON-US/go-btfs-chunker v0.2.8 github.com/TRON-US/go-btfs-cmds v0.1.6 github.com/TRON-US/go-btfs-config v0.4.7 - github.com/TRON-US/go-btfs-files v0.1.5 + github.com/TRON-US/go-btfs-files v0.1.6 github.com/TRON-US/go-eccrypto v0.0.1 github.com/TRON-US/go-mfs v0.2.2 - github.com/TRON-US/go-unixfs v0.5.8 + github.com/TRON-US/go-unixfs v0.5.9 github.com/TRON-US/interface-go-btfs-core v0.5.4 github.com/Workiva/go-datastructures v1.0.50 github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf @@ -152,9 +152,3 @@ replace github.com/ipfs/go-ipld-format => github.com/TRON-US/go-ipld-format v0.1 replace github.com/ipfs/go-cid => github.com/TRON-US/go-cid v0.1.0 replace github.com/libp2p/go-libp2p-core => github.com/TRON-US/go-libp2p-core v0.4.1 - -replace github.com/TRON-US/go-btfs-files => ../go-btfs-files - -replace github.com/TRON-US/go-unixfs => ../go-unixfs - -replace github.com/TRON-US/go-btfs-chunker => ../go-btfs-chunker diff --git a/go.sum b/go.sum index 17b2d6868..7e45130ef 100644 --- a/go.sum +++ b/go.sum @@ -38,10 +38,18 @@ github.com/Stebalien/go-bitfield v0.0.1 h1:X3kbSSPUaJK60wV2hjOPZwmpljr6VGCqdq4cB github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s= github.com/TRON-US/go-btfs-api v0.1.0 h1:YRS/RF2lSWlUJE2CaCnfpNsUu/OEpic1AXnGBX/PXQc= github.com/TRON-US/go-btfs-api v0.1.0/go.mod h1:XoXb4w+3ZF665lSdbhCDnINII2lEdwi4pAItlpdZVHI= +github.com/TRON-US/go-btfs-chunker v0.2.2/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= +github.com/TRON-US/go-btfs-chunker v0.2.3/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= +github.com/TRON-US/go-btfs-chunker v0.2.4/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= +github.com/TRON-US/go-btfs-chunker v0.2.8 h1:oUSEhjIZlJ52AVCXna4UqZEStH+xPEBCcZbWpTyAols= +github.com/TRON-US/go-btfs-chunker v0.2.8/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= github.com/TRON-US/go-btfs-cmds v0.1.6 h1:r1JCcAfWxGHpFxZpmlQN3NTEqbN9BRmX4ximfmBh2ok= github.com/TRON-US/go-btfs-cmds v0.1.6/go.mod h1:rtki4vmPzq7qmjdzThJELFpSpxTiORoXreHlExdI6eg= github.com/TRON-US/go-btfs-config v0.4.7 h1:ZK/eRkVQWqSIumzHcJ6kb2OKJwzZfhh3OINQjEjK8Fc= github.com/TRON-US/go-btfs-config v0.4.7/go.mod h1:045+FmBpTIWNy34ISzjtPaEf6afBq6wVQtviNmAnF5g= +github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0= +github.com/TRON-US/go-btfs-files v0.1.6 h1:POR7n7UUIMNtjIDEloqqi1/pRua2Gn5asjMJZsfiSxI= +github.com/TRON-US/go-btfs-files v0.1.6/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE= github.com/TRON-US/go-cid v0.1.0 h1:54gblgLGL2S3mJX3m3GyTdKVqJVUcG+kCkCqWjZvrdM= github.com/TRON-US/go-cid v0.1.0/go.mod h1:Rq2SnJvLEaPmL3B1JUHtVQ0b/GtkDtpY9BxDR537NPU= github.com/TRON-US/go-eccrypto v0.0.1 h1:+/5Uid61UGysbxv6Cv6gx4ru1gEiJOlir/P7ElAe7A0= @@ -52,6 +60,10 @@ github.com/TRON-US/go-libp2p-core v0.4.1 h1:vOTph4f42uxr2r2oAyCogIUxsHl2b5vWen2f github.com/TRON-US/go-libp2p-core v0.4.1/go.mod h1:B9V1MQtCLGp+jUXNdKJzNllFSsVSMuex1+5/fyWgYl0= github.com/TRON-US/go-mfs v0.2.2 h1:EUlDvvSo8HKso4oy05Ce8ZG6arASAdirV2BzAYfKTsM= github.com/TRON-US/go-mfs v0.2.2/go.mod h1:NduHl3CtI8J81aY4aV/Si/9XZbZ/+hHzPZUHC9Ho3WQ= +github.com/TRON-US/go-unixfs v0.4.4/go.mod h1:VBRlISp23R6JoJQ2t+O/VkIswnPo9PBVCh5blMpN0GI= +github.com/TRON-US/go-unixfs v0.4.12/go.mod h1:0Jv/z5OvpB4JpjJcUFB9turYohcoqjF/tmczQX9eeJ4= +github.com/TRON-US/go-unixfs v0.5.9 h1:fiwmZ9FEM3YkRUVsFD3fVFsAv8JJZShpv4YBok/VH7E= +github.com/TRON-US/go-unixfs v0.5.9/go.mod h1:TM3bRAMBsIbCj+oYN3e2dpnDe3ebrWRpQ1ZMtLUA2dY= github.com/TRON-US/interface-go-btfs-core v0.5.4 h1:rGtjXV8pRM0ap56XsI/lwB4vGUytS7mRrih0lmx+KJA= github.com/TRON-US/interface-go-btfs-core v0.5.4/go.mod h1:wZWJikVV3ShW7fClZP8/Gv8gYFg4ZowePkKBp0HY9Xc= github.com/VictoriaMetrics/fastcache v1.5.3/go.mod h1:+jv9Ckb+za/P1ZRg/sulP5Ni1v49daAVERr0H3CuscE= From 1d8944c4daabff7a6dc7a9f02d9eb1540fb80f4c Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Tue, 3 Mar 2020 17:58:39 -0800 Subject: [PATCH 10/36] BTFS-1586 --- core/coreunix/reed_solomon_add.go | 4 +--- core/coreunix/test/metadata_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/coreunix/reed_solomon_add.go b/core/coreunix/reed_solomon_add.go index 63b852902..39f14a5f3 100644 --- a/core/coreunix/reed_solomon_add.go +++ b/core/coreunix/reed_solomon_add.go @@ -227,13 +227,11 @@ func (rsadder *ReedSolomonAdder) addFile(path string, file files.File) (uio.Node if err != nil { return nil, err } - case SerialFile: + case SerialFile, SliceFile: fSize, err = file.Size() if err != nil { return nil, err } - case SliceFile: - return nil, errors.New("SliceFile type is not supported") default: return nil, errors.New("unsupported file type") } diff --git a/core/coreunix/test/metadata_test.go b/core/coreunix/test/metadata_test.go index 41f550142..049352b44 100644 --- a/core/coreunix/test/metadata_test.go +++ b/core/coreunix/test/metadata_test.go @@ -212,6 +212,15 @@ func addDirectoryToBtfs(node *core.IpfsNode, file files.Node, metadata string, r return nil, err } rsfileAdder.IsDir = true + if files.IsMultiPartDirectory(dir) { + rsfileAdder.FileType = coreunix.MultipartFile + } else if files.IsMapDirectory(dir) { + rsfileAdder.FileType = coreunix.SliceFile + } else if files.IsSerialFileDirectory(dir) { + rsfileAdder.FileType = coreunix.SerialFile + } else { + return nil, fmt.Errorf("unexpected files.Directory type [%T]", dir) + } } go func() { defer close(output) From 7dd265af57ef0bde878f4b620cd7d48bd45b4771 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Wed, 4 Mar 2020 18:52:43 -0500 Subject: [PATCH 11/36] 1.0.4-dev version bump --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index 3afdc4756..f33d38097 100644 --- a/version.go +++ b/version.go @@ -4,6 +4,6 @@ package ipfs var CurrentCommit string // CurrentVersionNumber is the current application's version literal -const CurrentVersionNumber = "1.0.3-dev" +const CurrentVersionNumber = "1.0.4-dev" const ApiVersion = "/go-btfs/" + CurrentVersionNumber + "/" From 35bca28e5984c88bb63c5e43f5becba559b91c3a Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Fri, 6 Mar 2020 16:15:57 -0500 Subject: [PATCH 12/36] go-btfs-common update to remove node_ip --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2fc21846b..6f11b336a 100644 --- a/go.mod +++ b/go.mod @@ -123,7 +123,7 @@ require ( github.com/shirou/gopsutil v2.19.11+incompatible github.com/stretchr/testify v1.4.0 github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d - github.com/tron-us/go-btfs-common v0.2.25 + github.com/tron-us/go-btfs-common v0.2.28 github.com/tron-us/protobuf v1.3.4 github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef diff --git a/go.sum b/go.sum index 7e45130ef..d74614ab6 100644 --- a/go.sum +++ b/go.sum @@ -895,8 +895,8 @@ github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4C github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tron-us/go-btfs-common v0.2.11/go.mod h1:9ND33JahGMg52sCC2/gO5DakLsd1Pg2lVe2CihW7lBE= -github.com/tron-us/go-btfs-common v0.2.25 h1:p3x/fEBnNn46o3wTOHiUi0j524w3WckOU1WOy0nC6jY= -github.com/tron-us/go-btfs-common v0.2.25/go.mod h1:FbYoo6ZrtnJH3TKdyJTGQrUP2rbwNVATQpxplwaYQ/c= +github.com/tron-us/go-btfs-common v0.2.28 h1:0UUp5JY5MUK24hg/hKvz9aeJqYpOqyNZ6z38ljySKQM= +github.com/tron-us/go-btfs-common v0.2.28/go.mod h1:FbYoo6ZrtnJH3TKdyJTGQrUP2rbwNVATQpxplwaYQ/c= github.com/tron-us/go-common/v2 v2.0.5 h1:LiGEmOd0FVVRisFyg3AJWDWMXlM537M3JZ+gh75sBlw= github.com/tron-us/go-common/v2 v2.0.5/go.mod h1:GiKX9noBLHotkZAU+7ET4h7N0DYWnm3OcGHOFJg1Q68= github.com/tron-us/protobuf v1.3.4 h1:oqokl6jMAfe1fb/B6t1UMllbw/KtfdJcCn8plxPkHM8= From 10247450883b905d3b01445a23e992f2103f6d50 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Sun, 8 Mar 2020 11:17:31 -0400 Subject: [PATCH 13/36] BTFS-1509: implement sync and display host storage stats --- core/commands/storage.go | 79 ++++++++++++++++++++++------- core/commands/storage/stats.go | 50 ++++++++++++++++++ core/commands/storage/stats_test.go | 45 ++++++++++++++++ core/hub/sync.go | 33 ++++++++++-- 4 files changed, 185 insertions(+), 22 deletions(-) create mode 100644 core/commands/storage/stats.go create mode 100644 core/commands/storage/stats_test.go diff --git a/core/commands/storage.go b/core/commands/storage.go index 217e346dd..2a0610015 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -13,11 +13,11 @@ import ( "github.com/TRON-US/go-btfs/core/commands/cmdenv" "github.com/TRON-US/go-btfs/core/commands/storage" "github.com/TRON-US/go-btfs/core/corehttp/remote" + "github.com/TRON-US/go-btfs/core/corerepo" "github.com/TRON-US/go-btfs/core/escrow" "github.com/TRON-US/go-btfs/core/guard" "github.com/TRON-US/go-btfs/core/hub" - coreiface "github.com/TRON-US/interface-go-btfs-core" - "github.com/TRON-US/interface-go-btfs-core/path" + "github.com/tron-us/go-btfs-common/crypto" escrowpb "github.com/tron-us/go-btfs-common/protos/escrow" guardpb "github.com/tron-us/go-btfs-common/protos/guard" @@ -26,6 +26,8 @@ import ( cmds "github.com/TRON-US/go-btfs-cmds" config "github.com/TRON-US/go-btfs-config" + coreiface "github.com/TRON-US/interface-go-btfs-core" + "github.com/TRON-US/interface-go-btfs-core/path" "github.com/Workiva/go-datastructures/set" "github.com/alecthomas/units" "github.com/cenkalti/backoff/v3" @@ -1509,7 +1511,7 @@ Mode options include:` + hub.AllModeHelpText, } func SyncHosts(ctx context.Context, node *core.IpfsNode, mode string) error { - nodes, err := hub.QueryHub(ctx, node, mode) + nodes, err := hub.QueryHosts(ctx, node, mode) if err != nil { return err } @@ -1903,13 +1905,44 @@ var storageStatsSyncCmd = &cmds.Command{ ShortDescription: ` This command synchronize node stats from network(hub) to local node data store.`, }, - Arguments: []cmds.Argument{}, - RunTimeout: 3 * time.Second, + Arguments: []cmds.Argument{}, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { - return nil + cfg, err := cmdenv.GetConfig(env) + if err != nil { + return err + } + if !cfg.Experimental.StorageHostEnabled { + return fmt.Errorf("storage host api not enabled") + } + + n, err := cmdenv.GetNode(env) + if err != nil { + return err + } + + return SyncStats(req.Context, cfg, n) }, } +func SyncStats(ctx context.Context, cfg *config.Config, node *core.IpfsNode) error { + sr, err := hub.QueryStats(ctx, node) + if err != nil { + return err + } + stat, err := corerepo.RepoStat(ctx, node) + if err != nil { + return err + } + hs := &nodepb.StorageStat_Host{ + Online: cfg.Experimental.StorageHostEnabled, + Uptime: sr.Uptime, + Score: sr.Score, + StorageUsed: int64(stat.RepoSize), + StorageCap: int64(stat.StorageMax), + } + return storage.SaveHostStatsIntoDatastore(ctx, node, node.Identity.Pretty(), hs) +} + // sub-commands: btfs storage stats info var storageStatsInfoCmd = &cmds.Command{ Helptext: cmds.HelpText{ @@ -1920,20 +1953,28 @@ This command get node stats in the network from the local node data store.`, Arguments: []cmds.Argument{}, RunTimeout: 3 * time.Second, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { - // return mock -- static dummy - data := map[string]interface{}{ - "HostStats": map[string]interface{}{ - "Online": true, - "Uptime": 86400, - "Score": 6.5, - "StorageUsed": 1024, - "StorageCap": 102400, - }, - "RenterStats": map[string]interface{}{ - "Reserved": "Reserved", - }, + cfg, err := cmdenv.GetConfig(env) + if err != nil { + return err } - return cmds.EmitOnce(res, data) + if !cfg.Experimental.StorageHostEnabled { + return fmt.Errorf("storage host api not enabled") + } + + n, err := cmdenv.GetNode(env) + if err != nil { + return err + } + + hs, err := storage.GetHostStatsFromDatastore(req.Context, n, n.Identity.Pretty()) + if err != nil { + return err + } + + // Only host stats for now + return cmds.EmitOnce(res, &nodepb.StorageStat{ + HostStats: *hs, + }) }, Type: nodepb.StorageStat{}, } diff --git a/core/commands/storage/stats.go b/core/commands/storage/stats.go new file mode 100644 index 000000000..92dc645b2 --- /dev/null +++ b/core/commands/storage/stats.go @@ -0,0 +1,50 @@ +package storage + +import ( + "context" + + "github.com/TRON-US/go-btfs/core" + + nodepb "github.com/tron-us/go-btfs-common/protos/node" + + "github.com/gogo/protobuf/proto" + ds "github.com/ipfs/go-datastore" +) + +const ( + HostStatStorePrefix = "/host_stats/" // from btfs-hub +) + +// GetHostStatsFromDatastore retrieves host storage stats based on node id +func GetHostStatsFromDatastore(ctx context.Context, node *core.IpfsNode, nodeId string) (*nodepb.StorageStat_Host, error) { + rds := node.Repo.Datastore() + qr, err := rds.Get(GetHostStatStorageKey(nodeId)) + if err != nil { + return nil, err + } + var hs nodepb.StorageStat_Host + err = proto.Unmarshal(qr, &hs) + if err != nil { + return nil, err + } + return &hs, nil +} + +func GetHostStatStorageKey(pid string) ds.Key { + return newKeyHelper(HostStatStorePrefix, pid) +} + +// SaveHostStatsIntoDatastore overwrites host storage stats based on node id +func SaveHostStatsIntoDatastore(ctx context.Context, node *core.IpfsNode, nodeId string, + stats *nodepb.StorageStat_Host) error { + rds := node.Repo.Datastore() + b, err := proto.Marshal(stats) + if err != nil { + return err + } + err = rds.Put(GetHostStatStorageKey(nodeId), b) + if err != nil { + return err + } + return nil +} diff --git a/core/commands/storage/stats_test.go b/core/commands/storage/stats_test.go new file mode 100644 index 000000000..b50f688ce --- /dev/null +++ b/core/commands/storage/stats_test.go @@ -0,0 +1,45 @@ +package storage + +import ( + "bytes" + "context" + "testing" + + unixtest "github.com/TRON-US/go-btfs/core/coreunix/test" + + nodepb "github.com/tron-us/go-btfs-common/protos/node" + + "github.com/gogo/protobuf/proto" +) + +func TestHostStatsSaveGet(t *testing.T) { + node := unixtest.HelpTestMockRepo(t, nil) + + hs := &nodepb.StorageStat_Host{ + Online: true, + Uptime: 0.95, + Score: 0.88, + StorageUsed: 100000, + StorageCap: 10000000, + } + nodeId := node.Identity.Pretty() + err := SaveHostStatsIntoDatastore(context.Background(), node, nodeId, hs) + if err != nil { + t.Fatal(err) + } + stored, err := GetHostStatsFromDatastore(context.Background(), node, nodeId) + if err != nil { + t.Fatal(err) + } + bs1, err := proto.Marshal(hs) + if err != nil { + t.Fatal(err) + } + bs2, err := proto.Marshal(stored) + if err != nil { + t.Fatal(err) + } + if bytes.Compare(bs1, bs2) != 0 { + t.Fatal("stored stats do not match saved stats") + } +} diff --git a/core/hub/sync.go b/core/hub/sync.go index 8f27756f3..4bd8c4842 100644 --- a/core/hub/sync.go +++ b/core/hub/sync.go @@ -39,9 +39,9 @@ func CheckValidMode(mode string, local bool) (hubpb.HostsReq_Mode, string, error return -1, "", fmt.Errorf("Invalid Hub query mode: %s", mode) } -// QueryHub queries the BTFS-Hub to retrieve the latest list of hosts info +// QueryHosts queries the BTFS-Hub to retrieve the latest list of hosts info // according to a certain mode. -func QueryHub(ctx context.Context, node *core.IpfsNode, mode string) ([]*hubpb.Host, error) { +func QueryHosts(ctx context.Context, node *core.IpfsNode, mode string) ([]*hubpb.Host, error) { hrm, _, err := CheckValidMode(mode, false) if err != nil { return nil, err @@ -66,8 +66,35 @@ func QueryHub(ctx context.Context, node *core.IpfsNode, mode string) ([]*hubpb.H return nil }) if err != nil { - return nil, fmt.Errorf("Failed to query BTFS-Hub service: %v", err) + return nil, fmt.Errorf("Failed to query hosts from Hub service: %v", err) } return resp.Hosts.Hosts, nil } + +// QueryStats queries the BTFS-Hub to retrieve the latest storage stats on this host. +func QueryStats(ctx context.Context, node *core.IpfsNode) (*hubpb.StatsResp, error) { + config, err := node.Repo.Config() + if err != nil { + return nil, err + } + var resp *hubpb.StatsResp + err = grpc.HubQueryClient(config.Services.HubDomain).WithContext(ctx, func(ctx context.Context, + client hubpb.HubQueryServiceClient) error { + resp, err = client.GetStats(ctx, &hubpb.StatsReq{ + Id: node.Identity.Pretty(), + }) + if err != nil { + return err + } + if resp.Code != hubpb.ResponseCode_SUCCESS { + return fmt.Errorf(resp.Message) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("Failed to query stats from Hub service: %v", err) + } + + return resp, nil +} From 08dbf9f743d91e4ab30a1e94d4f624dfc6259491 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Sun, 8 Mar 2020 13:15:01 -0400 Subject: [PATCH 14/36] Unify and spin sync hosts, stats and settings. --- cmd/btfs/daemon.go | 1 - spin/hosts.go | 44 +++++++++++++++++++++++++++++++++----------- spin/settings.go | 26 -------------------------- 3 files changed, 33 insertions(+), 38 deletions(-) delete mode 100644 spin/settings.go diff --git a/cmd/btfs/daemon.go b/cmd/btfs/daemon.go index b104a4ec8..eb89bdf3c 100644 --- a/cmd/btfs/daemon.go +++ b/cmd/btfs/daemon.go @@ -498,7 +498,6 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment // Spin jobs in the background spin.Analytics(cctx.ConfigRoot, node, version.CurrentVersionNumber, hValue) spin.Hosts(node) - spin.Settings(node) // Give the user some immediate feedback when they hit C-c go func() { diff --git a/spin/hosts.go b/spin/hosts.go index 00d34e875..04f2e19d1 100644 --- a/spin/hosts.go +++ b/spin/hosts.go @@ -7,35 +7,57 @@ import ( "github.com/TRON-US/go-btfs/core" "github.com/TRON-US/go-btfs/core/commands" + "github.com/TRON-US/go-btfs/core/hub" ) const ( - syncPeriod = 60 * time.Minute + hostSyncPeriod = 60 * time.Minute + hostStatsSyncPeriod = 30 * time.Minute + hostSettingsSyncPeriod = 60 * time.Minute + hostSyncTimeout = 30 * time.Second ) func Hosts(node *core.IpfsNode) { - configuration, err := node.Repo.Config() + cfg, err := node.Repo.Config() if err != nil { log.Errorf("Failed to get configuration %s", err) return } - if configuration.Experimental.HostsSyncEnabled { - m := configuration.Experimental.HostsSyncMode - fmt.Printf("Hosts info will be synced at [%s] mode\n", m) - - go periodicSyncHosts(node, m) + if cfg.Experimental.HostsSyncEnabled { + m := cfg.Experimental.HostsSyncMode + fmt.Printf("Storage host info will be synced at [%s] mode\n", m) + go periodicHostSync(hostSyncPeriod, hostSyncTimeout, "hosts", + func(ctx context.Context) error { + return commands.SyncHosts(ctx, node, m) + }) + } + if cfg.Experimental.StorageHostEnabled { + fmt.Println("Current host stats will be synced") + go periodicHostSync(hostStatsSyncPeriod, hostSyncTimeout, "host stats", + func(ctx context.Context) error { + return commands.SyncStats(ctx, cfg, node) + }) + fmt.Println("Current host settings will be synced") + go periodicHostSync(hostSettingsSyncPeriod, hostSyncTimeout, "host settings", + func(ctx context.Context) error { + _, err = hub.GetSettings(ctx, cfg.Services.HubDomain, node.Identity.Pretty(), + node.Repo.Datastore()) + return err + }) } } -func periodicSyncHosts(node *core.IpfsNode, mode string) { - tick := time.NewTicker(syncPeriod) +func periodicHostSync(period, timeout time.Duration, msg string, syncFunc func(context.Context) error) { + tick := time.NewTicker(period) defer tick.Stop() // Force tick on immediate start for ; true; <-tick.C { - err := commands.SyncHosts(context.Background(), node, mode) + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + err := syncFunc(ctx) if err != nil { - log.Errorf("Failed to sync hosts: %s", err) + log.Errorf("Failed to sync %s: %s", msg, err) } } } diff --git a/spin/settings.go b/spin/settings.go deleted file mode 100644 index 81e568787..000000000 --- a/spin/settings.go +++ /dev/null @@ -1,26 +0,0 @@ -package spin - -import ( - "github.com/TRON-US/go-btfs/core" - "github.com/TRON-US/go-btfs/core/hub" -) - -func Settings(node *core.IpfsNode) { - c, err := node.Repo.Config() - if err != nil { - log.Errorf("Failed to get configuration %s", err) - return - } - - if c.Experimental.StorageHostEnabled { - go func() { - _, err := hub.GetSettings(node.Context(), c.Services.HubDomain, node.Identity.Pretty(), - node.Repo.Datastore()) - if err != nil { - log.Error("error occured when getting settings, error: ", err.Error()) - } - }() - } - - //TODO: spin -} From 1d9f7eaa32c163adb7f87adf59e76976f5bde4f7 Mon Sep 17 00:00:00 2001 From: tycm4109 <32829113+tycm4109@users.noreply.github.com> Date: Sun, 8 Mar 2020 23:14:51 -0700 Subject: [PATCH 15/36] Update help commands Made the following updates: 1. Updated BTT to JUST, updated price values 2. Updated host storage price and bandwidth to Min, instead of Max. --- core/commands/storage.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index 217e346dd..1950fcb09 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -143,7 +143,7 @@ Use status command to check for completion: }, Options: []cmds.Option{ cmds.BoolOption(leafHashOptionName, "l", "Flag to specify given hash(es) is leaf hash(es).").WithDefault(false), - cmds.Int64Option(uploadPriceOptionName, "p", "Max price per GiB per day of storage in BTT."), + cmds.Int64Option(uploadPriceOptionName, "p", "Max price per GiB per day of storage in JUST."), cmds.IntOption(replicationFactorOptionName, "r", "Replication factor for the file with erasure coding built-in.").WithDefault(defaultRepFactor), cmds.StringOption(hostSelectModeOptionName, "m", "Based on this mode to select hosts and upload automatically. Default: mode set in config option Experimental.HostsSyncMode."), cmds.StringOption(hostSelectionOptionName, "s", "Use only these selected hosts in order on 'custom' mode. Use ',' as delimiter."), @@ -1569,13 +1569,13 @@ This command updates host information and broadcasts to the BTFS network. Examples -To set the max price per GiB to 1 BTT: +To set the min price per GiB to 1000000 JUST (1 BTT): $ btfs storage announce --host-storage-price=1`, }, Options: []cmds.Option{ - cmds.Uint64Option(hostStoragePriceOptionName, "s", "Max price per GiB of storage per day in BTT."), - cmds.Uint64Option(hostBandwidthPriceOptionName, "b", "Max price per MiB of bandwidth in BTT."), - cmds.Uint64Option(hostCollateralPriceOptionName, "cl", "Max collateral stake per hour per GiB in BTT."), + cmds.Uint64Option(hostStoragePriceOptionName, "s", "Min price per GiB of storage per day in JUST."), + cmds.Uint64Option(hostBandwidthPriceOptionName, "b", "Min price per MiB of bandwidth in JUST."), + cmds.Uint64Option(hostCollateralPriceOptionName, "cl", "Max collateral stake per hour per GiB in JUST."), cmds.FloatOption(hostBandwidthLimitOptionName, "l", "Max bandwidth limit per MB/s."), cmds.Uint64Option(hostStorageTimeMinOptionName, "d", "Min number of days for storage."), cmds.Uint64Option(hostStorageMaxOptionName, "m", "Max number of GB this host provides for storage."), From 2fafa217b9c3a1ee75e04bd19140ececb17633bb Mon Sep 17 00:00:00 2001 From: tycm4109 <32829113+tycm4109@users.noreply.github.com> Date: Mon, 9 Mar 2020 11:06:18 -0700 Subject: [PATCH 16/36] Updated sample command Updated sample command to be 1000000 JUST --- core/commands/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index 1950fcb09..8d2da2d33 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -1570,7 +1570,7 @@ This command updates host information and broadcasts to the BTFS network. Examples To set the min price per GiB to 1000000 JUST (1 BTT): -$ btfs storage announce --host-storage-price=1`, +$ btfs storage announce --host-storage-price=1000000`, }, Options: []cmds.Option{ cmds.Uint64Option(hostStoragePriceOptionName, "s", "Min price per GiB of storage per day in JUST."), From 2e055f5913af33719509f621b610a30a06524969 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Tue, 10 Mar 2020 17:02:24 -0700 Subject: [PATCH 17/36] BTFS-1663: Add static embed of host ui files to /hostui --- cmd/btfs/daemon.go | 2 ++ cmd/ipfswatch/main.go | 1 + core/corehttp/hostui.go | 5 +++++ core/corehttp/static.go | 17 +++++++++++++++++ go.mod | 3 ++- go.sum | 6 ++++++ hostui/index.html | 3 +++ pkged.go | 10 ++++++++++ 8 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 core/corehttp/hostui.go create mode 100644 core/corehttp/static.go create mode 100644 hostui/index.html create mode 100644 pkged.go diff --git a/cmd/btfs/daemon.go b/cmd/btfs/daemon.go index eb89bdf3c..3d6d78eb7 100644 --- a/cmd/btfs/daemon.go +++ b/cmd/btfs/daemon.go @@ -549,6 +549,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error apiMaddr = apiLis.Multiaddr() fmt.Printf("API server listening on %s\n", apiMaddr) fmt.Printf("WebUI: http://%s/webui\n", apiLis.Addr()) + fmt.Printf("HostUI: http://%s/hostui\n", apiLis.Addr()) listeners = append(listeners, apiLis) } @@ -567,6 +568,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error corehttp.CheckVersionOption(), corehttp.CommandsOption(*cctx), corehttp.WebUIOption, + corehttp.HostUIOption, gatewayOpt, corehttp.VersionOption(), defaultMux("/debug/vars"), diff --git a/cmd/ipfswatch/main.go b/cmd/ipfswatch/main.go index 36af7ae14..573fc5bb8 100644 --- a/cmd/ipfswatch/main.go +++ b/cmd/ipfswatch/main.go @@ -94,6 +94,7 @@ func run(ipfsPath, watchPath string) error { var opts = []corehttp.ServeOption{ corehttp.GatewayOption(true, "/btfs", "/btns"), corehttp.WebUIOption, + corehttp.HostUIOption, corehttp.CommandsOption(cmdCtx(node, ipfsPath)), } proc.Go(func(p process.Process) { diff --git a/core/corehttp/hostui.go b/core/corehttp/hostui.go new file mode 100644 index 000000000..2eb5beb87 --- /dev/null +++ b/core/corehttp/hostui.go @@ -0,0 +1,5 @@ +package corehttp + +const HostUIDir = "/hostui" + +var HostUIOption = StaticOption("hostui", HostUIDir) diff --git a/core/corehttp/static.go b/core/corehttp/static.go new file mode 100644 index 000000000..372981263 --- /dev/null +++ b/core/corehttp/static.go @@ -0,0 +1,17 @@ +package corehttp + +import ( + "net" + "net/http" + + "github.com/TRON-US/go-btfs/core" + + "github.com/markbates/pkger" +) + +func StaticOption(path, dir string) ServeOption { + return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { + mux.Handle("/"+path+"/", http.FileServer(pkger.Dir(dir))) + return mux, nil + } +} diff --git a/go.mod b/go.mod index 6f11b336a..f32ff76ab 100644 --- a/go.mod +++ b/go.mod @@ -104,6 +104,7 @@ require ( github.com/libp2p/go-libp2p-yamux v0.2.1 github.com/libp2p/go-maddr-filter v0.0.5 github.com/libp2p/go-testutil v0.1.0 + github.com/markbates/pkger v0.14.1 github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect github.com/mholt/archiver v3.1.1+incompatible github.com/mitchellh/go-homedir v1.1.0 @@ -140,7 +141,7 @@ require ( golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd gopkg.in/cheggaaa/pb.v1 v1.0.28 gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect - gopkg.in/yaml.v2 v2.2.4 + gopkg.in/yaml.v2 v2.2.7 gotest.tools/gotestsum v0.3.4 launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect ) diff --git a/go.sum b/go.sum index d74614ab6..e88a1184a 100644 --- a/go.sum +++ b/go.sum @@ -227,6 +227,8 @@ github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUD github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= github.com/go-toolsmith/typep v1.0.0 h1:zKymWyA1TRYvqYrYDrfEMZULyrhcnGY3x7LDKU2XQaA= github.com/go-toolsmith/typep v1.0.0/go.mod h1:JSQCQMUPdRlMZFswiq3TGpNp1GMktqkR2Ns5AIQkATU= +github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI= +github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gofrs/flock v0.0.0-20190320160742-5135e617513b h1:ekuhfTjngPhisSjOJ0QWKpPQE8/rbknHaes6WVJj5Hw= @@ -683,6 +685,8 @@ github.com/lucas-clemente/quic-go v0.11.2 h1:Mop0ac3zALaBR3wGs6j8OYe/tcFvFsxTUFM github.com/lucas-clemente/quic-go v0.11.2/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/markbates/pkger v0.14.1 h1:1m+0+lGqRsoWuImV+zQ558ogRhNoS0ufflM/xxhzARA= +github.com/markbates/pkger v0.14.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI= github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNAI4vA= github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb h1:RHba4YImhrUVQDHUCe2BNSOz4tVy2yGyXhvYDvxGgeE= @@ -1121,6 +1125,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= +gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.1.0+incompatible h1:5USw7CrJBYKqjg9R7QlA6jzqZKEAtvW82aNmsxxGPxw= gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= diff --git a/hostui/index.html b/hostui/index.html new file mode 100644 index 000000000..d857967b5 --- /dev/null +++ b/hostui/index.html @@ -0,0 +1,3 @@ + +Host UI Dashboard + diff --git a/pkged.go b/pkged.go new file mode 100644 index 000000000..4c295ee09 --- /dev/null +++ b/pkged.go @@ -0,0 +1,10 @@ +// Code generated by pkger; DO NOT EDIT. + +package main + +import ( + "github.com/markbates/pkger" + "github.com/markbates/pkger/pkging/mem" +) + +var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec52c16adc3014fc153167d922b4f4a06359127ad8b4ec6e7a29a13c4b6f6d5159cf48724a59f6df8b37c9b63410da9e72c8c91e899937a3370784b497027b401fea3077ad93d1ec361faf9b9bade9a5e9eafe74bb0a1916e6a6702e867370a61753b233bfd16a96d4cce54cd3f8304e92eb27aa03ec730334ae69645884e98456e260f17e77b955a128527d948ea256779c4b90c45eab893937559ae5abf62172f9512a8fd0d851eeb93e753b7deb8da7fc3da4af34fa776f9fb1de123436224f55a0b1a6ea06d82f6871abb1ad1419b6e6991fc086a948824592aa422a956264afbab92abaa310a98bac4252dd1ca2578edcc0d0b892cb25c4a2ebc5b5a7490f711770fbf8980536cd316aac783affefb8d4b3c0afa33f186bf1f3e2f580bfd9c89a427accf57fdbbf92b5f87fe5995eda51fc89fef93e3f2c2eda8b37381e8f1afbfb9087a3c6c0995fbbf9dacd17d2cd9f000000ffff010000ffffc3d8a4dc4c050000`))) From b3eff52e658daacbec8f091af2ae8cab91084110 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Tue, 10 Mar 2020 17:05:12 -0700 Subject: [PATCH 18/36] Sync top level package to btfs --- doc.go | 2 +- pkged.go | 2 +- version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc.go b/doc.go index 25cc64776..22d1cfe6e 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,4 @@ /* BTFS is a global, versioned, peer-to-peer filesystem */ -package ipfs +package btfs diff --git a/pkged.go b/pkged.go index 4c295ee09..cb7c939a4 100644 --- a/pkged.go +++ b/pkged.go @@ -1,6 +1,6 @@ // Code generated by pkger; DO NOT EDIT. -package main +package btfs import ( "github.com/markbates/pkger" diff --git a/version.go b/version.go index f33d38097..a178fdf86 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ -package ipfs +package btfs // CurrentCommit is the current git commit, this is set as a ldflag in the Makefile var CurrentCommit string From 676903cee1634325e99a5e5c11ba52e99102f234 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Tue, 10 Mar 2020 17:42:16 -0700 Subject: [PATCH 19/36] BTFS-1698 --- core/commands/storage.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index 859f442c7..08f2183a9 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -399,7 +399,7 @@ Upload a file with offline signing. I.e., SDK application acts as renter.`, if err != nil { return err } - hashes, _, err := storage.CheckAndGetReedSolomonShardHashes(req.Context, n, api, rootHash) + hashes, fileSize, err := storage.CheckAndGetReedSolomonShardHashes(req.Context, n, api, rootHash) if err != nil || len(hashes) == 0 { return fmt.Errorf("invalid hash: %s", err) } @@ -438,6 +438,7 @@ Upload a file with offline signing. I.e., SDK application acts as renter.`, return err } + output.ss.SetFileSize(fileSize) go retryMonitor(api, output.ss, n, output.ssID, output.testFlag, runMode, renterPid.Pretty(), false, 1) From 0c0d1fee3f736bac4897702ba28c69e17b630655 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Tue, 10 Mar 2020 17:59:41 -0700 Subject: [PATCH 20/36] BTFS-1698 --- core/commands/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index 08f2183a9..3e55d5804 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -438,7 +438,7 @@ Upload a file with offline signing. I.e., SDK application acts as renter.`, return err } - output.ss.SetFileSize(fileSize) + output.ss.SetFileSize(fileSize) // set session file size go retryMonitor(api, output.ss, n, output.ssID, output.testFlag, runMode, renterPid.Pretty(), false, 1) From 56f05756b834841f3bbe68b367a77eae223d5123 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Wed, 11 Mar 2020 04:29:16 -0700 Subject: [PATCH 21/36] Fix static path --- core/corehttp/static.go | 2 +- pkged.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/corehttp/static.go b/core/corehttp/static.go index 372981263..255a8c74f 100644 --- a/core/corehttp/static.go +++ b/core/corehttp/static.go @@ -11,7 +11,7 @@ import ( func StaticOption(path, dir string) ServeOption { return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { - mux.Handle("/"+path+"/", http.FileServer(pkger.Dir(dir))) + mux.Handle("/"+path+"/", http.StripPrefix(dir, http.FileServer(pkger.Dir(dir)))) return mux, nil } } diff --git a/pkged.go b/pkged.go index cb7c939a4..8b0996b96 100644 --- a/pkged.go +++ b/pkged.go @@ -7,4 +7,4 @@ import ( "github.com/markbates/pkger/pkging/mem" ) -var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec52c16adc3014fc153167d922b4f4a06359127ad8b4ec6e7a29a13c4b6f6d5159cf48724a59f6df8b37c9b63410da9e72c8c91e899937a3370784b497027b401fea3077ad93d1ec361faf9b9bade9a5e9eafe74bb0a1916e6a6702e867370a61753b233bfd16a96d4cce54cd3f8304e92eb27aa03ec730334ae69645884e98456e260f17e77b955a128527d948ea256779c4b90c45eab893937559ae5abf62172f9512a8fd0d851eeb93e753b7deb8da7fc3da4af34fa776f9fb1de123436224f55a0b1a6ea06d82f6871abb1ad1419b6e6991fc086a948824592aa422a956264afbab92abaa310a98bac4252dd1ca2578edcc0d0b892cb25c4a2ebc5b5a7490f711770fbf8980536cd316aac783affefb8d4b3c0afa33f186bf1f3e2f580bfd9c89a427accf57fdbbf92b5f87fe5995eda51fc89fef93e3f2c2eda8b37381e8f1afbfb9087a3c6c0995fbbf9dacd17d2cd9f000000ffff010000ffffc3d8a4dc4c050000`))) +var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec97dd72e23614c75f8539b71558b20cb675d724139a6d49b340b6edec6418610b5bf587184b90ee6678f78e6c6c48b34b76db9dee0dc38524ebfca5f3c5cfe32790e54a69604f9048936e96834815ce7cfaeb6dff7ee624aabf34ab7af74a56c0c0b9d7a2d28ea864e424cad155e41cc94ca5cafe4677320437c55a55e68e9b14d8a90b10dcf2420083fdea4a45c0e0627e3deb49dde3bd24574b9ea3de56545aaa52c4a8b716a2ea1bd5b7636f2573a13f68230a4030e75522cc4b6fd759e2c4bc7a94e58217f1c83be1fa800382a9522f4f0104136ea214d87b18c0038299e1b90066aa8dd82fa6826b55da6036328f7b3757bd42eaa2162118ab6bebab95c72a1ad407eea3b28b8736671a58b9c973045762ddcde7429bee80c3a37f28262ade58979ee04b123fe1b26cddff77451eab898abf56e7246a50a8b896bf6be20706644028ec763b04ab26c8536dc99c5469b391d6ca76b11d6361b8cc6b61d974d4de0681961f05b07084a050b100e612cff7028f78a47eb230b2b677b18bfb98f6099e13c25ccc86788043e21297f87e1ffb0c634020f522b6c96af2a63f34ff11b1054646beefbb2eaeeb20ec3af07d04b7b92c336014c14da980d15110b8e17084e05ec6c086982018db99154e637b104670c7e34594a80506f61ea3faf780e047eba95e8bc8de39b3031906341879ded04570abed93d0c381eb52ba4330f9bc39eeccf7f1ed105c7e9df985ac4cfa39090d3b893f0c5d37747dbc4330eb2a7191ab28d375ac1779d654c8c376e73ae749b33116653dfea2d7bc12f5f4ed7e6a93f250b74b2aaa33a53e4da913017d1b7cadb344c467927d926408d6b5e74f7097255fd85d2dd67608626e789b0cdbf2a5391c7510d4f7bcce494796b1f86b909a223f8dcc23bb169b94b6d8f42ca14ef1d20b076140477ee092e10b5eae78ae5f0126a524083a60922360523c0cbf3130472d9fdcc0f369e0517292985ed821b00df124328fec43dff36880c3d798f9fc8ee18850423b66da32b4cc0cbe1f339deea5fa0c9d878eecf61b441ee3ee80ac03a49a06dfa368df22cf59748c9ec6fa0c97ff02976316749c81bb718a97bf3dfe7099a5db88be4ddedd67c9747cfd918fdf6cfff8fd4d76f9e7e396ff3435cb2bef677885484d8389f35bf9fcedf0ff7e3bfc0d0000ffff010000ffff2df8c596d30e0000`))) From 691b1c30b120e81924fa6181665bb4db642368ac Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Wed, 11 Mar 2020 04:59:32 -0700 Subject: [PATCH 22/36] Add Makefile target for refreshing hostui --- mk/util.mk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mk/util.mk b/mk/util.mk index 352918402..46aab6fb7 100644 --- a/mk/util.mk +++ b/mk/util.mk @@ -38,6 +38,10 @@ join-with=$(subst $(space),$1,$(strip $2)) print-%: @echo $*=$($*) +# generate static host ui +hostui: + pkger -include /hostui + # phony target that will mean that recipe is always exectued ALWAYS: -.PHONY: ALWAYS +.PHONY: ALWAYS hostui From 0fbe7b9dacfc0428bf1e878687695ce93c3285aa Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Wed, 11 Mar 2020 15:42:52 -0700 Subject: [PATCH 23/36] BTFS-1698 --- core/commands/storage.go | 327 ++++++++++++++++++++------------------- 1 file changed, 166 insertions(+), 161 deletions(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index 3e55d5804..b4a70d1cb 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -174,28 +174,89 @@ Use status command to check for completion: if err != nil { return err } - var ( - shardHashes []string - rootHash cidlib.Cid - shardSize uint64 - renterPid = n.Identity - ) runMode := storage.RegularMode - lf := req.Options[leafHashOptionName].(bool) - var fileSize int64 - if !lf { - if len(req.Arguments) != 1 { - return fmt.Errorf("need one and only one root file hash") - } - // get leaf hashes - hashStr := req.Arguments[0] - // convert to cid - rootHash, err = cidlib.Parse(hashStr) - if err != nil { - return err + output, err := openSession(¶msForOpenSession{ + req: req, + n: n, + api: api, + cfg: cfg, + ctx: req.Context, + runMode: runMode, + }) + if err != nil { + return err + } + + go retryMonitor(api, output.ss, n, output.ssID, output.testFlag, + runMode, output.renterPid.Pretty(), output.customizedSchedule, output.period) + + seRes := &UploadRes{ + ID: output.ssID, + } + return res.Emit(seRes) + }, + Type: UploadRes{}, +} + +func parseRequest(param *paramsForOpenSession) error { + req := param.req + n := param.n + api := param.api + runMode := param.runMode + var ( + err error + shardHashes []string + rootHash cidlib.Cid + shardSize uint64 + renterPid = n.Identity + fileSize int64 + // Next element is only for storage.RepairMode + blacklist = set.New() + // Next elements are only for storage.OfflineSignMode + offPeerId peer.ID + offNonceTimestamp uint64 + offSessionSignature string + ) + + lf := req.Options[leafHashOptionName].(bool) + if lf { + rootHash = cidlib.Undef + shardHashes = req.Arguments + shardCid, err := cidlib.Parse(shardHashes[0]) + if err != nil { + return err + } + fileSize = -1 // we don't need file size in this case + shardSize, err = getContractSizeFromCid(req.Context, shardCid, api) + if err != nil { + return err + } + } else { + + if runMode == storage.RegularMode && len(req.Arguments) != 1 { + return fmt.Errorf("need one and only one root file hash") + } else if runMode == storage.OfflineSignMode && len(req.Arguments) != 4 { + return fmt.Errorf("need file hash, offline-peer-id, offline-nonce-timestamp, and session-signature") + } + if runMode == storage.RegularMode && len(req.Arguments) > 3 { + blacklistStr := req.Arguments[3] + for _, s := range strings.Split(blacklistStr, ",") { + blacklist.Add(s) } + param.blacklist = blacklist + } + + // get root hash + hashStr := req.Arguments[0] + // convert to cid + rootHash, err = cidlib.Parse(hashStr) + if err != nil { + return err + } + + if runMode == storage.RegularMode || runMode == storage.OfflineSignMode { hashes, tmp, err := storage.CheckAndGetReedSolomonShardHashes(req.Context, n, api, rootHash) if err != nil || len(hashes) == 0 { return fmt.Errorf("invalid hash: %s", err) @@ -209,45 +270,56 @@ Use status command to check for completion: for _, h := range hashes { shardHashes = append(shardHashes, h.String()) } - } else { - rootHash = cidlib.Undef - shardHashes = req.Arguments + + if runMode == storage.OfflineSignMode { + offPeerId, err = peer.IDB58Decode(req.Arguments[1]) + if err != nil { + return err + } + offNonceTimestamp, err = strconv.ParseUint(req.Arguments[2], 10, 64) + if err != nil { + return err + } + offSessionSignature = req.Arguments[3] + + param.offPeerId = offPeerId + param.offNonceTimestamp = offNonceTimestamp + param.offSessionSignature = offSessionSignature + } + } else if runMode == storage.RepairMode { + renterPid, err = peer.IDB58Decode(req.Arguments[2]) + if err != nil { + return err + } + shardHashes = strings.Split(req.Arguments[1], ",") + for _, h := range shardHashes { + _, err := cidlib.Parse(h) + if err != nil { + return err + } + } shardCid, err := cidlib.Parse(shardHashes[0]) if err != nil { return err } - fileSize = -1 // we don't need file size in this case shardSize, err = getContractSizeFromCid(req.Context, shardCid, api) if err != nil { return err } + param.renterPid = renterPid + } else { + return fmt.Errorf("unexpected runMode [%d]", runMode) } + } - output, err := openSession(¶msForOpenSession{ - req: req, - n: n, - cfg: cfg, - ctx: req.Context, - rootHash: rootHash, - runMode: runMode, - shardHashes: shardHashes, - blacklist: set.New(), - shardSize: shardSize, - }) - if err != nil { - return err - } - - output.ss.SetFileSize(fileSize) - go retryMonitor(api, output.ss, n, output.ssID, output.testFlag, - runMode, renterPid.Pretty(), output.customizedSchedule, output.period) + // Set common output items + param.shardHashes = shardHashes + param.rootHash = rootHash + param.shardSize = shardSize + param.fileSize = fileSize + param.renterPid = renterPid - seRes := &UploadRes{ - ID: output.ssID, - } - return res.Emit(seRes) - }, - Type: UploadRes{}, + return nil } var storageUploadRepairCmd = &cmds.Command{ @@ -281,62 +353,23 @@ This command repairs the given shards of a file.`, if err != nil { return err } - var ( - shardHashes []string - rootHash cidlib.Cid - shardSize uint64 - blacklist = set.New() - renterPid = n.Identity - ) - runMode := storage.RepairMode - if len(req.Arguments) > 3 { - blacklistStr := req.Arguments[3] - for _, s := range strings.Split(blacklistStr, ",") { - blacklist.Add(s) - } - } - rootHash, err = cidlib.Parse(req.Arguments[0]) - if err != nil { - return err - } - renterPid, err = peer.IDB58Decode(req.Arguments[2]) - if err != nil { - return err - } - shardHashes = strings.Split(req.Arguments[1], ",") - for _, h := range shardHashes { - _, err := cidlib.Parse(h) - if err != nil { - return err - } - } - shardCid, err := cidlib.Parse(shardHashes[0]) - if err != nil { - return err - } - shardSize, err = getContractSizeFromCid(req.Context, shardCid, api) - if err != nil { - return err - } + runMode := storage.RepairMode output, err := openSession(¶msForOpenSession{ - req: req, - n: n, - cfg: cfg, - ctx: req.Context, - rootHash: rootHash, - runMode: runMode, - shardHashes: shardHashes, - blacklist: set.New(), - shardSize: shardSize, + req: req, + n: n, + api: api, + cfg: cfg, + ctx: req.Context, + runMode: runMode, }) if err != nil { return err } go retryMonitor(api, output.ss, n, output.ssID, output.testFlag, - runMode, renterPid.Pretty(), false, 1) + runMode, output.renterPid.Pretty(), false, 1) seRes := &UploadRes{ ID: output.ssID, @@ -379,91 +412,52 @@ Upload a file with offline signing. I.e., SDK application acts as renter.`, if err != nil { return err } - // check file hash - var ( - shardHashes []string - rootHash cidlib.Cid - shardSize uint64 - renterPid = n.Identity - offPeerId peer.ID - offNonceTimestamp uint64 - offSessionSignature string - ) runMode := storage.OfflineSignMode - if len(req.Arguments) != 4 { - return fmt.Errorf("need file hash, offline-peer-id, offline-nonce-timestamp, and session-signature") - } - hashStr := req.Arguments[0] - rootHash, err = cidlib.Parse(hashStr) - if err != nil { - return err - } - hashes, fileSize, err := storage.CheckAndGetReedSolomonShardHashes(req.Context, n, api, rootHash) - if err != nil || len(hashes) == 0 { - return fmt.Errorf("invalid hash: %s", err) - } - // get shard size - shardSize, err = getContractSizeFromCid(req.Context, hashes[0], api) - if err != nil { - return err - } - for _, h := range hashes { - shardHashes = append(shardHashes, h.String()) - } - offPeerId, err = peer.IDB58Decode(req.Arguments[1]) - if err != nil { - return err - } - offNonceTimestamp, err = strconv.ParseUint(req.Arguments[2], 10, 64) - if err != nil { - return err - } - offSessionSignature = req.Arguments[3] - output, err := openSession(¶msForOpenSession{ - req: req, - n: n, - cfg: cfg, - ctx: req.Context, - rootHash: rootHash, - runMode: runMode, - shardHashes: shardHashes, - offPeerId: offPeerId, - offNonceTimestamp: offNonceTimestamp, - offSessionSignature: offSessionSignature, - shardSize: shardSize, + req: req, + n: n, + api: api, + cfg: cfg, + ctx: req.Context, + runMode: runMode, }) if err != nil { return err } - output.ss.SetFileSize(fileSize) // set session file size go retryMonitor(api, output.ss, n, output.ssID, output.testFlag, - runMode, renterPid.Pretty(), false, 1) + runMode, output.renterPid.Pretty(), false, 1) seRes := &UploadRes{ ID: output.ssID, } return res.Emit(seRes) - }, Type: UploadRes{}, } type paramsForOpenSession struct { - req *cmds.Request - n *core.IpfsNode - cfg *config.Config - ctx context.Context - rootHash cidlib.Cid - runMode int - shardHashes []string - blacklist *set.Set - offPeerId peer.ID - offNonceTimestamp uint64 - offSessionSignature string - shardSize uint64 + req *cmds.Request + n *core.IpfsNode + api coreiface.CoreAPI + cfg *config.Config + ctx context.Context + runMode int + + // The rest of the fields to the end are + // set from parseRequest() and output to openSession() + shardHashes []string + rootHash cidlib.Cid + shardSize uint64 + renterPid peer.ID + fileSize int64 + + blacklist *set.Set // only for storage.RepairMode + + offPeerId peer.ID // only for storage.OfflineMode + offNonceTimestamp uint64 // only for storage.OfflineMode + offSessionSignature string // only for storage.OfflineMode } type outputOfOpenSession struct { @@ -472,13 +466,20 @@ type outputOfOpenSession struct { testFlag bool customizedSchedule bool period int + renterPid peer.ID } func openSession(param *paramsForOpenSession) (*outputOfOpenSession, error) { - // TODO: Genereate session ID on new req := param.req n := param.n cfg := param.cfg + runMode := param.runMode + + // Parse + err := parseRequest(param) + if err != nil { + return nil, err + } // create a new session sm := storage.GlobalSession @@ -489,7 +490,7 @@ func openSession(param *paramsForOpenSession) (*outputOfOpenSession, error) { ss := sm.GetOrDefault(ssID, param.n.Identity) // initialize the session - ss.Initialize(param.rootHash, param.runMode) + ss.Initialize(param.rootHash, runMode) go controlSessionTimeout(ss, storage.StdSessionStateFlow[0:]) @@ -592,12 +593,16 @@ func openSession(param *paramsForOpenSession) (*outputOfOpenSession, error) { // create main session context ss.RetryMonitorCtx = storage.NewGoContext(param.ctx) + // Set upload session file size. + ss.SetFileSize(param.fileSize) + return &outputOfOpenSession{ ss: ss, ssID: ssID, testFlag: testFlag, customizedSchedule: customizedPayout, period: p, + renterPid: param.renterPid, }, nil } From d167ddce18fefa60796b4bcd3cc82ef8d77b4572 Mon Sep 17 00:00:00 2001 From: tycm4109 <32829113+tycm4109@users.noreply.github.com> Date: Wed, 11 Mar 2020 20:35:32 -0700 Subject: [PATCH 24/36] Update with build instructions Updating Readme with build from source instructions. Including MacOS, Linux VM, and docker. --- README.md | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/README.md b/README.md index 85be6f544..27229aec6 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ contracts. - [Install](#install) - [System Requirements](#system-requirements) +- [Build from Source](#build-from-source) + - [MacOS](#macos) + - [Linux VM](#linux-vm) + - [Docker](#docker) - [Usage](#usage) - [Getting Started](#getting-started) - [Some things to try](#some-things-to-try) @@ -56,6 +60,119 @@ Start the BTFS Daemon $ btfs daemon ``` +## Build from Source + +### MacOS + +Clone the go-btfs repository +``` +$ git clone https://github.com/TRON-US/go-btfs +``` + +Navigate to the go-btfs directory and run `make install`. +``` +$ cd go-btfs +$ make install +``` + +A successful make install outputs something like: +``` +$ make install +go: downloading github.com/tron-us/go-btfs-common v0.2.28 +go: extracting github.com/tron-us/go-btfs-common v0.2.28 +go: finding github.com/tron-us/go-btfs-common v0.2.28 +go version go1.13.1 darwin/amd64 +bin/check_go_version 1.13 +bash patching.sh +go install "-asmflags=all='-trimpath='" "-gcflags=all='-trimpath='" -ldflags="-X "github.com/TRON-US/go-btfs".CurrentCommit=e4848946d" ./cmd/btfs +``` + +Afterwards, run `btfs init` and `btfs daemon` to initialize and start the daemon. + +### Linux VM + +Developers wishing to run a BTFS daemon on a Linux VM should first set up the environment. On an AWS EC2 Linux machine for example, it would be helpful to first install the following tools and dependencies: +``` +$ sudo yum update // Installs general updates for Linux +$ sudo yum install git // Lets you git clone the go-btfs repository +$ sudo yum install patch // Required for building from source +$ sudo yum install gcc // Required for building from source +``` + +Building BTFS from source requires Go 1.13 or higher. To install from the terminal: +``` +$ cd /tmp +$ GO_PACKAGE=go1.13.linux-amd64.tar.gz +$ wget https://golang.org/dl/$GO_PACKAGE +$ sudo tar -xvf $GO_PACKAGE +$ sudo mv go /usr/local +$ sudo rm $GO_PACKAGE +``` + +Navigate back to root directory and set the Go Path in the environment variables: +``` +$ export GOPATH=${HOME}/go +$ export PATH=$PATH:/usr/local/go/bin +$ export PATH=$PATH:$GOPATH/bin +$ export GO111MODULE=on +``` + +Verify the Go version is 1.13 or higher: +``` +$ go version +``` + +Navigate to the go-btfs directory and run `make install`. +``` +$ cd go-btfs +$ make install +``` + +Afterwards, run `btfs init` and `btfs daemon` to initialize and start the daemon. To re-initialize a new pair of keys, you can shut down the daemon first via `btfs shutdown`. Then run `rm -r .btfs` and `btfs init` again. + +### Docker + +Developers also have the option to build a BTFS daemon within a Docker container. After cloning the go-btfs repository, navigate into the go-btfs directory. This is where the Dockerfile is located. Build the docker image: +``` +$ cd go-btfs +$ docker image build -t btfs_docker . // Builds the docker image and tags "btfs_docker" as the name +``` + +A successful build should have an output like: +``` +Sending build context to Docker daemon 2.789MB +Step 1/37 : FROM golang:1.13-stretch + ---> 4fe257ac564c +Step 2/37 : MAINTAINER TRON-US + ---> Using cache + ---> 02409001f528 + +... + +Step 37/37 : CMD ["daemon", "--migrate=true"] + ---> Running in 3660f91dce94 +Removing intermediate container 3660f91dce94 + ---> b4e1523cf264 +Successfully built b4e1523cf264 +Successfully tagged btfs_docker:latest +``` + +Start the container based on the new image. Starting the container also initializes and starts the BTFS daemon. +``` +$ docker container run --publish 5001:8080 --detach --name btfs1 btfs_docker +``` + +The CLI flags are as such: + +`--publish` asks Docker to forward traffic incoming on the host’s port 5001, to the container’s port 8080. +`--detach` asks Docker to run this container in the background. +`--name` specifies a name with which you can refer to your container in subsequent commands, in this case btfs1. + +Execute commands within the docker container: +``` +docker exec CONTAINER btfs add chunker=reed-solomon FILE +``` + ## Usage ``` From c522c2265607783458c1dee39b4e0c2fd2398b0c Mon Sep 17 00:00:00 2001 From: tycm4109 <32829113+tycm4109@users.noreply.github.com> Date: Wed, 11 Mar 2020 20:36:50 -0700 Subject: [PATCH 25/36] Update Readme List formatting --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 27229aec6..2e6c4b4fc 100644 --- a/README.md +++ b/README.md @@ -164,9 +164,9 @@ $ docker container run --publish 5001:8080 --detach --name btfs1 btfs_docker The CLI flags are as such: -`--publish` asks Docker to forward traffic incoming on the host’s port 5001, to the container’s port 8080. -`--detach` asks Docker to run this container in the background. -`--name` specifies a name with which you can refer to your container in subsequent commands, in this case btfs1. +* `--publish` asks Docker to forward traffic incoming on the host’s port 5001, to the container’s port 8080. +* `--detach` asks Docker to run this container in the background. +* `--name` specifies a name with which you can refer to your container in subsequent commands, in this case btfs1. Execute commands within the docker container: ``` From 853582f9e0e210eb62061497f3f1accf3488180c Mon Sep 17 00:00:00 2001 From: Junlin Gao Date: Thu, 12 Mar 2020 12:17:05 -0700 Subject: [PATCH 26/36] if the daemon is not running, ask the deposit wait for confirm done. --- core/commands/wallet.go | 12 +++++++++++- core/wallet/transaction.go | 12 ++++++++---- core/wallet/wallet.go | 4 ++-- go.mod | 1 + go.sum | 2 ++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/core/commands/wallet.go b/core/commands/wallet.go index 0e849c001..7c613744d 100644 --- a/core/commands/wallet.go +++ b/core/commands/wallet.go @@ -74,12 +74,22 @@ var walletDepositCmd = &cmds.Command{ return err } - err = wallet.WalletDeposit(cfg, amount) + runDaemon := false + currentNode, err := cmdenv.GetNode(env) + if err != nil { + log.Error("wrong while get current Node, continue the program ", err) + } + runDaemon = currentNode.IsDaemon + + err = wallet.WalletDeposit(cfg, amount, runDaemon) if err != nil { log.Error("wallet deposit failed, ERR: ", err) return err } s := fmt.Sprintf("BTFS wallet deposit submitted. Please wait one minute for the transaction to confirm.") + if !runDaemon { + s = fmt.Sprintf("BTFS wallet deposit Done.") + } return cmds.EmitOnce(res, &MessageOutput{s}) }, Encoders: cmds.EncoderMap{ diff --git a/core/wallet/transaction.go b/core/wallet/transaction.go index 7c782b3d2..880c09239 100644 --- a/core/wallet/transaction.go +++ b/core/wallet/transaction.go @@ -24,7 +24,7 @@ var ( ) // Do the deposit action, integrate exchange's PrepareDeposit and Deposit API. -func Deposit(ledgerAddr []byte, amount int64, privateKey *ecdsa.PrivateKey) (*exPb.PrepareDepositResponse, error) { +func Deposit(ledgerAddr []byte, amount int64, privateKey *ecdsa.PrivateKey, runDaemon bool) (*exPb.PrepareDepositResponse, error) { log.Debug("Deposit begin!") //PrepareDeposit prepareResponse, err := PrepareDeposit(ledgerAddr, amount) @@ -50,10 +50,14 @@ func Deposit(ledgerAddr []byte, amount int64, privateKey *ecdsa.PrivateKey) (*ex } log.Debug(fmt.Sprintf("Call Deposit API success, id: [%d]", prepareResponse.GetId())) - // Doing confirm deposit. - go func() { + if runDaemon { + go func() { + ConfirmDepositProcess(prepareResponse, privateKey) + }() + } else { ConfirmDepositProcess(prepareResponse, privateKey) - }() + } + // Doing confirm deposit. log.Debug("Deposit end!") return prepareResponse, nil diff --git a/core/wallet/wallet.go b/core/wallet/wallet.go index 8dd8c216b..9c322dd6c 100644 --- a/core/wallet/wallet.go +++ b/core/wallet/wallet.go @@ -80,7 +80,7 @@ func WalletWithdraw(configuration *config.Config, amount int64) error { return nil } -func WalletDeposit(configuration *config.Config, amount int64) error { +func WalletDeposit(configuration *config.Config, amount int64, runDaemon bool) error { err := Init(configuration) if err != nil { return err @@ -95,7 +95,7 @@ func WalletDeposit(configuration *config.Config, amount int64) error { return errors.New(fmt.Sprintf("deposit amount should between %d ~ %d", DepositMinAmount, DepositMaxAmount)) } - prepareResponse, err := Deposit(hostWallet.ledgerAddress, amount, hostWallet.privateKey) + prepareResponse, err := Deposit(hostWallet.ledgerAddress, amount, hostWallet.privateKey, runDaemon) if err != nil { log.Error("Failed to Deposit, ERR[%v]\n", err) return err diff --git a/go.mod b/go.mod index f32ff76ab..d8a30afb1 100644 --- a/go.mod +++ b/go.mod @@ -72,6 +72,7 @@ require ( github.com/ipfs/hang-fds v0.0.1 github.com/ipfs/iptb v1.4.0 github.com/ipfs/iptb-plugins v0.1.0 + github.com/jbenet/go-fuse-version v0.0.0-20160322195114-6d4c97bcf253 // indirect github.com/jbenet/go-is-domain v1.0.2 github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c github.com/jbenet/go-random-files v0.0.0-20190219210431-31b3f20ebded diff --git a/go.sum b/go.sum index e88a1184a..783defe33 100644 --- a/go.sum +++ b/go.sum @@ -451,6 +451,8 @@ github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= +github.com/jbenet/go-fuse-version v0.0.0-20160322195114-6d4c97bcf253 h1:+AUuGGAh/2X3wcomiZvjeTcx5OvGXsfdnIqk3KPM+HE= +github.com/jbenet/go-fuse-version v0.0.0-20160322195114-6d4c97bcf253/go.mod h1:gWtF+3u3zVe5/+I44niTEcU/KmVo2oMyLh0WhxpBT28= github.com/jbenet/go-is-domain v1.0.2 h1:11r5MSptcNFZyBoqubBQnVMUKRWLuRjL1banaIk+iYo= github.com/jbenet/go-is-domain v1.0.2/go.mod h1:xbRLRb0S7FgzDBTJlguhDVwLYM/5yNtvktxj2Ttfy7Q= github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c h1:uUx61FiAa1GI6ZmVd2wf2vULeQZIKG66eybjNXKYCz4= From f46ef1277f6da5449a6164a20de1414705f33d8a Mon Sep 17 00:00:00 2001 From: Junlin Gao Date: Thu, 12 Mar 2020 12:29:10 -0700 Subject: [PATCH 27/36] address coding review comments --- core/commands/wallet.go | 3 ++- core/wallet/transaction.go | 4 +--- go.mod | 1 - go.sum | 2 -- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/core/commands/wallet.go b/core/commands/wallet.go index 7c613744d..0d4d84ca2 100644 --- a/core/commands/wallet.go +++ b/core/commands/wallet.go @@ -77,7 +77,8 @@ var walletDepositCmd = &cmds.Command{ runDaemon := false currentNode, err := cmdenv.GetNode(env) if err != nil { - log.Error("wrong while get current Node, continue the program ", err) + log.Error("Wrong while get current Node information", err) + return err } runDaemon = currentNode.IsDaemon diff --git a/core/wallet/transaction.go b/core/wallet/transaction.go index 880c09239..ec5dc8206 100644 --- a/core/wallet/transaction.go +++ b/core/wallet/transaction.go @@ -51,9 +51,7 @@ func Deposit(ledgerAddr []byte, amount int64, privateKey *ecdsa.PrivateKey, runD log.Debug(fmt.Sprintf("Call Deposit API success, id: [%d]", prepareResponse.GetId())) if runDaemon { - go func() { - ConfirmDepositProcess(prepareResponse, privateKey) - }() + go ConfirmDepositProcess(prepareResponse, privateKey) } else { ConfirmDepositProcess(prepareResponse, privateKey) } diff --git a/go.mod b/go.mod index d8a30afb1..f32ff76ab 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,6 @@ require ( github.com/ipfs/hang-fds v0.0.1 github.com/ipfs/iptb v1.4.0 github.com/ipfs/iptb-plugins v0.1.0 - github.com/jbenet/go-fuse-version v0.0.0-20160322195114-6d4c97bcf253 // indirect github.com/jbenet/go-is-domain v1.0.2 github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c github.com/jbenet/go-random-files v0.0.0-20190219210431-31b3f20ebded diff --git a/go.sum b/go.sum index 783defe33..e88a1184a 100644 --- a/go.sum +++ b/go.sum @@ -451,8 +451,6 @@ github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= -github.com/jbenet/go-fuse-version v0.0.0-20160322195114-6d4c97bcf253 h1:+AUuGGAh/2X3wcomiZvjeTcx5OvGXsfdnIqk3KPM+HE= -github.com/jbenet/go-fuse-version v0.0.0-20160322195114-6d4c97bcf253/go.mod h1:gWtF+3u3zVe5/+I44niTEcU/KmVo2oMyLh0WhxpBT28= github.com/jbenet/go-is-domain v1.0.2 h1:11r5MSptcNFZyBoqubBQnVMUKRWLuRjL1banaIk+iYo= github.com/jbenet/go-is-domain v1.0.2/go.mod h1:xbRLRb0S7FgzDBTJlguhDVwLYM/5yNtvktxj2Ttfy7Q= github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c h1:uUx61FiAa1GI6ZmVd2wf2vULeQZIKG66eybjNXKYCz4= From c75deb515c43126a44acaf82cc1dd312164b9c20 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Thu, 12 Mar 2020 15:12:38 -0700 Subject: [PATCH 28/36] BTFS-1712 --- core/commands/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index b4a70d1cb..afc04893f 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -540,7 +540,7 @@ func openSession(param *paramsForOpenSession) (*outputOfOpenSession, error) { return nil, err } for _, ni := range hosts { - if param.blacklist == nil || param.blacklist.Exists(ni) { + if param.blacklist != nil && param.blacklist.Exists(ni) { continue } // use host askingPrice instead if provided From a607ba95d8219bac44e5684b750d77761c721d24 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Fri, 13 Mar 2020 14:24:40 -0700 Subject: [PATCH 29/36] BTFS-1651 --- core/commands/storage.go | 13 +++++++++++-- core/commands/storage_offline.go | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index afc04893f..36a13bfd4 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -272,16 +272,25 @@ func parseRequest(param *paramsForOpenSession) error { } if runMode == storage.OfflineSignMode { - offPeerId, err = peer.IDB58Decode(req.Arguments[1]) + offPeerIdStr := req.Arguments[1] + offPeerId, err = peer.IDB58Decode(offPeerIdStr) if err != nil { return err } - offNonceTimestamp, err = strconv.ParseUint(req.Arguments[2], 10, 64) + offNTStr := req.Arguments[2] + offNonceTimestamp, err = strconv.ParseUint(offNTStr, 10, 64) if err != nil { return err } offSessionSignature = req.Arguments[3] + // Verify the given session signature + inputDataStr := fmt.Sprintf("%s%s%s", hashStr, offPeerIdStr, offNTStr) + + err = VerifySessionSignature(offPeerId, inputDataStr, offSessionSignature) + if err != nil { + return err + } param.offPeerId = offPeerId param.offNonceTimestamp = offNonceTimestamp param.offSessionSignature = offSessionSignature diff --git a/core/commands/storage_offline.go b/core/commands/storage_offline.go index c96f2e80d..17fca6296 100644 --- a/core/commands/storage_offline.go +++ b/core/commands/storage_offline.go @@ -31,6 +31,24 @@ const ( GuardOffSignOperation = "guard" ) +func VerifySessionSignature(offSignRenterPid peer.ID, data string, sessionSigStr string) error { + // get renter's public key + pubKey, err := offSignRenterPid.ExtractPublicKey() + if err != nil { + return err + } + + sigBytes, err := stringToBytes(sessionSigStr, Base64) + if err != nil { + return err + } + ok, err := pubKey.Verify([]byte(data), sigBytes) + if !ok || err != nil { + return fmt.Errorf("can't verify session signature: %v", err) + } + return nil +} + func prepareSignedContractsForShardOffSign(param *paramsForPrepareContractsForShard, candidateHost *storage.HostNode, initialCall bool) error { shard := param.shard From b7be51326c9a26d679a2b9b016d34fe9b8238eb5 Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Fri, 13 Mar 2020 15:18:21 -0700 Subject: [PATCH 30/36] BTFS-1651 --- core/commands/storage_offline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/storage_offline.go b/core/commands/storage_offline.go index 17fca6296..cf394addb 100644 --- a/core/commands/storage_offline.go +++ b/core/commands/storage_offline.go @@ -44,7 +44,7 @@ func VerifySessionSignature(offSignRenterPid peer.ID, data string, sessionSigStr } ok, err := pubKey.Verify([]byte(data), sigBytes) if !ok || err != nil { - return fmt.Errorf("can't verify session signature: %v", err) + return fmt.Errorf("cannot verify session signature: %v", err) } return nil } From 5fa49840fd5d97bd1d7d0078cd306b4c509aa762 Mon Sep 17 00:00:00 2001 From: Weiyu Xue Date: Fri, 13 Mar 2020 16:43:29 -0700 Subject: [PATCH 31/36] fix missing storage config fields in spin send --- spin/analytics.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spin/analytics.go b/spin/analytics.go index e51654771..3893c0535 100644 --- a/spin/analytics.go +++ b/spin/analytics.go @@ -2,7 +2,6 @@ package spin import ( "context" - "encoding/json" "fmt" "runtime" "strings" @@ -12,7 +11,6 @@ import ( "github.com/TRON-US/go-btfs/core/commands/storage" config "github.com/TRON-US/go-btfs-config" - "github.com/tron-us/go-btfs-common/info" nodepb "github.com/tron-us/go-btfs-common/protos/node" pb "github.com/tron-us/go-btfs-common/protos/status" cgrpc "github.com/tron-us/go-btfs-common/utils/grpc" @@ -129,9 +127,9 @@ func (dc *dcWrap) update(node *core.IpfsNode) []error { res = append(res, fmt.Errorf("cannot get selfKey: %s", err.Error())) } - var ns info.NodeStorage + var ns nodepb.Node_Settings if err == nil { - err = json.Unmarshal(b, &ns) + err = ns.Unmarshal(b) if err != nil { res = append(res, fmt.Errorf("cannot parse nodestorage config: %s", err.Error())) } else { From ac9998fa566c1a62a3e511beb6b5798c9c6afc7c Mon Sep 17 00:00:00 2001 From: Weiyu Xue Date: Fri, 13 Mar 2020 17:07:50 -0700 Subject: [PATCH 32/36] refactor: add GetHostStorageConfig() helper --- core/commands/storage/hosts.go | 12 ++++++++++++ spin/analytics.go | 33 +++++++++++++-------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/core/commands/storage/hosts.go b/core/commands/storage/hosts.go index c107a8fc8..f0a3d8779 100644 --- a/core/commands/storage/hosts.go +++ b/core/commands/storage/hosts.go @@ -10,6 +10,7 @@ import ( "github.com/TRON-US/go-btfs/repo" hubpb "github.com/tron-us/go-btfs-common/protos/hub" + nodepb "github.com/tron-us/go-btfs-common/protos/node" humanize "github.com/dustin/go-humanize" "github.com/gogo/protobuf/proto" @@ -63,6 +64,17 @@ func GetHostsFromDatastore(ctx context.Context, node *core.IpfsNode, mode string return hosts, nil } +func GetHostStorageConfig(node *core.IpfsNode) (nodepb.Node_Settings, error) { + var ns nodepb.Node_Settings + rds := node.Repo.Datastore() + b, err := rds.Get(GetHostStorageKey(node.Identity.Pretty())) + if err != nil && err != ds.ErrNotFound { + return ns, fmt.Errorf("cannot get selfKey: %s", err.Error()) + } + err = ns.Unmarshal(b) + return ns, err +} + func GetHostStorageKey(pid string) ds.Key { return newKeyHelper(HostStorageInfoPrefix, pid) } diff --git a/spin/analytics.go b/spin/analytics.go index 3893c0535..73adf7cc1 100644 --- a/spin/analytics.go +++ b/spin/analytics.go @@ -19,7 +19,6 @@ import ( "github.com/cenkalti/backoff/v3" "github.com/gogo/protobuf/proto" "github.com/ipfs/go-bitswap" - ds "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log" ic "github.com/libp2p/go-libp2p-crypto" "github.com/shirou/gopsutil/cpu" @@ -119,26 +118,20 @@ func Analytics(cfgRoot string, node *core.IpfsNode, BTFSVersion, hValue string) func (dc *dcWrap) update(node *core.IpfsNode) []error { var res []error - var m runtime.MemStats + var ( + m runtime.MemStats + ns nodepb.Node_Settings + ) runtime.ReadMemStats(&m) - rds := node.Repo.Datastore() - b, err := rds.Get(storage.GetHostStorageKey(node.Identity.Pretty())) - if err != nil && err != ds.ErrNotFound { - res = append(res, fmt.Errorf("cannot get selfKey: %s", err.Error())) - } - - var ns nodepb.Node_Settings - if err == nil { - err = ns.Unmarshal(b) - if err != nil { - res = append(res, fmt.Errorf("cannot parse nodestorage config: %s", err.Error())) - } else { - dc.pn.StoragePriceAsk = ns.StoragePriceAsk - dc.pn.BandwidthPriceAsk = ns.BandwidthPriceAsk - dc.pn.StorageTimeMin = ns.StorageTimeMin - dc.pn.BandwidthLimit = ns.BandwidthLimit - dc.pn.CollateralStake = ns.CollateralStake - } + ns, err := storage.GetHostStorageConfig(node) + if err != nil { + res = append(res, fmt.Errorf("failed to get node storage config: %s", err.Error())) + } else { + dc.pn.StoragePriceAsk = ns.StoragePriceAsk + dc.pn.BandwidthPriceAsk = ns.BandwidthPriceAsk + dc.pn.StorageTimeMin = ns.StorageTimeMin + dc.pn.BandwidthLimit = ns.BandwidthLimit + dc.pn.CollateralStake = ns.CollateralStake } dc.pn.UpTime = durationToSeconds(time.Since(dc.pn.TimeCreated)) From a93b81890c17f788f2937003bf39d6bc3652c02a Mon Sep 17 00:00:00 2001 From: Weiyu Xue Date: Fri, 13 Mar 2020 18:11:17 -0700 Subject: [PATCH 33/36] nulllable return --- core/commands/storage/hosts.go | 6 +++--- spin/analytics.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/commands/storage/hosts.go b/core/commands/storage/hosts.go index f0a3d8779..10f254936 100644 --- a/core/commands/storage/hosts.go +++ b/core/commands/storage/hosts.go @@ -64,15 +64,15 @@ func GetHostsFromDatastore(ctx context.Context, node *core.IpfsNode, mode string return hosts, nil } -func GetHostStorageConfig(node *core.IpfsNode) (nodepb.Node_Settings, error) { +func GetHostStorageConfig(node *core.IpfsNode) (*nodepb.Node_Settings, error) { var ns nodepb.Node_Settings rds := node.Repo.Datastore() b, err := rds.Get(GetHostStorageKey(node.Identity.Pretty())) if err != nil && err != ds.ErrNotFound { - return ns, fmt.Errorf("cannot get selfKey: %s", err.Error()) + return nil, fmt.Errorf("cannot get selfKey: %s", err.Error()) } err = ns.Unmarshal(b) - return ns, err + return &ns, err } func GetHostStorageKey(pid string) ds.Key { diff --git a/spin/analytics.go b/spin/analytics.go index 73adf7cc1..47704d16b 100644 --- a/spin/analytics.go +++ b/spin/analytics.go @@ -120,7 +120,7 @@ func (dc *dcWrap) update(node *core.IpfsNode) []error { var ( m runtime.MemStats - ns nodepb.Node_Settings + ns *nodepb.Node_Settings ) runtime.ReadMemStats(&m) ns, err := storage.GetHostStorageConfig(node) From 24501a392cd770e0026ced39b53f30cfa735307a Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Fri, 13 Mar 2020 20:11:00 -0700 Subject: [PATCH 34/36] BTFS-1674: Follow up to fix host announce not storing storage config --- core/commands/storage.go | 24 ++++--------- core/commands/storage/hosts.go | 52 +++++++++++++++++++++++++---- core/commands/storage/hosts_test.go | 32 ++++++++++++++++++ core/hub/settings.go | 22 ++---------- spin/analytics.go | 7 +++- spin/hosts.go | 5 ++- 6 files changed, 96 insertions(+), 46 deletions(-) diff --git a/core/commands/storage.go b/core/commands/storage.go index 36a13bfd4..021b06290 100644 --- a/core/commands/storage.go +++ b/core/commands/storage.go @@ -32,7 +32,6 @@ import ( "github.com/alecthomas/units" "github.com/cenkalti/backoff/v3" humanize "github.com/dustin/go-humanize" - "github.com/gogo/protobuf/proto" cidlib "github.com/ipfs/go-cid" ic "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" @@ -508,8 +507,7 @@ func openSession(param *paramsForOpenSession) (*outputOfOpenSession, error) { // init retry queue retryQueue := storage.NewRetryQueue(int64(len(peers))) // set price limit, the price is default when host doesn't provide price - ns, err := hub.GetSettings(param.ctx, cfg.Services.HubDomain, - n.Identity.String(), n.Repo.Datastore()) + ns, err := storage.GetHostStorageConfig(param.ctx, n) if err != nil { return nil, err } @@ -1229,7 +1227,7 @@ the shard and replies back to client for the next challenge step.`, halfSignedEscrowContBytes = []byte(halfSignedEscrowContString) halfSignedGuardContBytes = []byte(halfSignedGuardContString) - settings, err := hub.GetSettings(req.Context, cfg.Services.HubDomain, n.Identity.Pretty(), n.Repo.Datastore()) + settings, err := storage.GetHostStorageConfig(req.Context, n) if err != nil { return err } @@ -1562,14 +1560,14 @@ By default it shows local host node information.`, } // Default to self + var data *nodepb.Node_Settings var peerID string if len(req.Arguments) > 0 { peerID = req.Arguments[0] + data, err = storage.GetHostStorageConfigForPeer(n, peerID) } else { - peerID = n.Identity.Pretty() + data, err = storage.GetHostStorageConfig(req.Context, n) } - - data, err := hub.GetSettings(req.Context, cfg.Services.HubDomain, peerID, n.Repo.Datastore()) if err != nil { return err } @@ -1640,10 +1638,7 @@ $ btfs storage announce --host-storage-price=1000000`, return fmt.Errorf("maximum price is %d", bttTotalSupply) } - rds := n.Repo.Datastore() - peerId := n.Identity.Pretty() - - ns, err := hub.GetSettings(req.Context, cfg.Services.HubDomain, peerId, rds) + ns, err := storage.GetHostStorageConfig(req.Context, n) if err != nil { return err } @@ -1677,12 +1672,7 @@ $ btfs storage announce --host-storage-price=1000000`, } } - nb, err := proto.Marshal(ns) - if err != nil { - return err - } - - err = rds.Put(storage.GetHostStorageKey(peerId), nb) + err = storage.PutHostStorageConfig(n, ns) if err != nil { return err } diff --git a/core/commands/storage/hosts.go b/core/commands/storage/hosts.go index 10f254936..b10822e7e 100644 --- a/core/commands/storage/hosts.go +++ b/core/commands/storage/hosts.go @@ -64,15 +64,55 @@ func GetHostsFromDatastore(ctx context.Context, node *core.IpfsNode, mode string return hosts, nil } -func GetHostStorageConfig(node *core.IpfsNode) (*nodepb.Node_Settings, error) { - var ns nodepb.Node_Settings +// GetHostStorageConfigForPeer retrieves locally saved info about peer (including self) +func GetHostStorageConfigForPeer(node *core.IpfsNode, peerID string) (*nodepb.Node_Settings, error) { rds := node.Repo.Datastore() - b, err := rds.Get(GetHostStorageKey(node.Identity.Pretty())) - if err != nil && err != ds.ErrNotFound { - return nil, fmt.Errorf("cannot get selfKey: %s", err.Error()) + b, err := rds.Get(GetHostStorageKey(peerID)) + if err != nil { + return nil, err } + ns := new(nodepb.Node_Settings) err = ns.Unmarshal(b) - return &ns, err + if err != nil { + return nil, err + } + return ns, nil +} + +// GetHostStorageConfig checks if locally is storing a config, if yes, returns it, +// otherwise, queries hub to retrieve the latest default config. +func GetHostStorageConfig(ctx context.Context, node *core.IpfsNode) (*nodepb.Node_Settings, error) { + ns, err := GetHostStorageConfigForPeer(node, node.Identity.Pretty()) + if err != nil && err != ds.ErrNotFound { + return nil, fmt.Errorf("cannot get current host storage settings: %s", err.Error()) + } + // Exists + if err == nil { + return ns, nil + } + cfg, err := node.Repo.Config() + if err != nil { + return nil, err + } + ns, err = hub.GetHostSettings(ctx, cfg.Services.HubDomain, node.Identity.Pretty()) + if err != nil { + return nil, err + } + err = PutHostStorageConfig(node, ns) + if err != nil { + return nil, err + } + return ns, nil +} + +// PutHostStorageConfig saves an updated storage storage config. +func PutHostStorageConfig(node *core.IpfsNode, ns *nodepb.Node_Settings) error { + rds := node.Repo.Datastore() + b, err := ns.Marshal() + if err != nil { + return fmt.Errorf("cannot put current host storage settings: %s", err.Error()) + } + return rds.Put(GetHostStorageKey(node.Identity.Pretty()), b) } func GetHostStorageKey(pid string) ds.Key { diff --git a/core/commands/storage/hosts_test.go b/core/commands/storage/hosts_test.go index ac23cfa45..f734f346e 100644 --- a/core/commands/storage/hosts_test.go +++ b/core/commands/storage/hosts_test.go @@ -11,6 +11,7 @@ import ( "github.com/TRON-US/go-btfs/repo" hubpb "github.com/tron-us/go-btfs-common/protos/hub" + nodepb "github.com/tron-us/go-btfs-common/protos/node" config "github.com/TRON-US/go-btfs-config" "github.com/alecthomas/units" @@ -51,6 +52,37 @@ func TestHostsSaveGet(t *testing.T) { } } +func TestHostStorageConfigPutGet(t *testing.T) { + node := unixtest.HelpTestMockRepo(t, nil) + + ns := &nodepb.Node_Settings{ + StoragePriceAsk: 111111, + BandwidthPriceAsk: 111, + StorageTimeMin: 15, + BandwidthLimit: 999, + CollateralStake: 1000, + } + err := PutHostStorageConfig(node, ns) + if err != nil { + t.Fatal(err) + } + stored, err := GetHostStorageConfig(context.Background(), node) + if err != nil { + t.Fatal(err) + } + bs1, err := proto.Marshal(ns) + if err != nil { + t.Fatal(err) + } + bs2, err := proto.Marshal(stored) + if err != nil { + t.Fatal(err) + } + if bytes.Compare(bs1, bs2) != 0 { + t.Fatal("stored settings do not match saved settings") + } +} + func newSmCfg(max string) *config.Config { cfg := &config.Config{} cfg.Datastore.StorageMax = max diff --git a/core/hub/settings.go b/core/hub/settings.go index 48cd6e9c8..aee203267 100644 --- a/core/hub/settings.go +++ b/core/hub/settings.go @@ -3,32 +3,16 @@ package hub import ( "context" "errors" - "fmt" - "github.com/TRON-US/go-btfs/repo" hubpb "github.com/tron-us/go-btfs-common/protos/hub" nodepb "github.com/tron-us/go-btfs-common/protos/node" "github.com/tron-us/go-btfs-common/utils/grpc" - - "github.com/ipfs/go-datastore" -) - -var ( - keyFormat = "/btfs/%s/settings/v1" ) -func GetSettings(ctx context.Context, addr string, peerId string, rds datastore.Datastore) (*nodepb.Node_Settings, error) { - k := fmt.Sprintf(keyFormat, peerId) - s := new(nodepb.Node_Settings) - settings, err := repo.Get(rds, k, s) - if err == nil { - n := settings.(*nodepb.Node_Settings) - return n, nil - } - +func GetHostSettings(ctx context.Context, addr, peerId string) (*nodepb.Node_Settings, error) { // get from remote ns := new(nodepb.Node_Settings) - err = grpc.HubQueryClient(addr).WithContext(ctx, func(ctx context.Context, client hubpb.HubQueryServiceClient) error { + err := grpc.HubQueryClient(addr).WithContext(ctx, func(ctx context.Context, client hubpb.HubQueryServiceClient) error { req := new(hubpb.SettingsReq) req.Id = peerId resp, err := client.GetSettings(ctx, req) @@ -48,5 +32,5 @@ func GetSettings(ctx context.Context, addr string, peerId string, rds datastore. if err != nil { return nil, err } - return ns, repo.Put(rds, k, ns) + return ns, nil } diff --git a/spin/analytics.go b/spin/analytics.go index 47704d16b..efa3da8cb 100644 --- a/spin/analytics.go +++ b/spin/analytics.go @@ -42,6 +42,9 @@ const ( // Expotentially delayed retries will be capped at this total time maxRetryTotal = 10 * time.Minute + + // Timeout to retrieve settings/config + updateTimeout = 30 * time.Second ) //Go doesn't have a built in Max function? simple function to not have negatives values @@ -123,7 +126,9 @@ func (dc *dcWrap) update(node *core.IpfsNode) []error { ns *nodepb.Node_Settings ) runtime.ReadMemStats(&m) - ns, err := storage.GetHostStorageConfig(node) + ctx, cancel := context.WithTimeout(context.Background(), updateTimeout) + defer cancel() + ns, err := storage.GetHostStorageConfig(ctx, node) if err != nil { res = append(res, fmt.Errorf("failed to get node storage config: %s", err.Error())) } else { diff --git a/spin/hosts.go b/spin/hosts.go index 04f2e19d1..ab51d1222 100644 --- a/spin/hosts.go +++ b/spin/hosts.go @@ -7,7 +7,7 @@ import ( "github.com/TRON-US/go-btfs/core" "github.com/TRON-US/go-btfs/core/commands" - "github.com/TRON-US/go-btfs/core/hub" + "github.com/TRON-US/go-btfs/core/commands/storage" ) const ( @@ -41,8 +41,7 @@ func Hosts(node *core.IpfsNode) { fmt.Println("Current host settings will be synced") go periodicHostSync(hostSettingsSyncPeriod, hostSyncTimeout, "host settings", func(ctx context.Context) error { - _, err = hub.GetSettings(ctx, cfg.Services.HubDomain, node.Identity.Pretty(), - node.Repo.Datastore()) + _, err = storage.GetHostStorageConfig(ctx, node) return err }) } From 8aee360580a671d07e32ced64af82dae93ecdd37 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Fri, 13 Mar 2020 20:25:59 -0700 Subject: [PATCH 35/36] fix hub settings test --- core/hub/settings_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/hub/settings_test.go b/core/hub/settings_test.go index d85e10ac0..d3562cf37 100644 --- a/core/hub/settings_test.go +++ b/core/hub/settings_test.go @@ -2,19 +2,20 @@ package hub import ( "context" - "fmt" + "reflect" "testing" - "github.com/ipfs/go-datastore" - syncds "github.com/ipfs/go-datastore/sync" + nodepb "github.com/tron-us/go-btfs-common/protos/node" ) func TestGetSettings(t *testing.T) { - d := syncds.MutexWrap(datastore.NewMapDatastore()) - ns, err := GetSettings(context.Background(), "https://hub-dev.btfs.io", - "16Uiu2HAm9P1cur6Nhd542y7pM2EoXgVvGeNqdUCSLFAMooBeQqWy", d) + ns, err := GetHostSettings(context.Background(), "https://hub-staging.btfs.io", + "16Uiu2HAm9P1cur6Nhd542y7pM2EoXgVvGeNqdUCSLFAMooBeQqWy") if err != nil { t.Fatal(err) } - fmt.Println("settings", ns) + defNs := &nodepb.Node_Settings{StoragePriceAsk: 250000, StorageTimeMin: 30} + if !reflect.DeepEqual(ns, defNs) { + t.Fatal("default settings not equal") + } } From 990ce19a857aae5b5b7614f24257bb8397767056 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Mon, 16 Mar 2020 12:18:04 -0700 Subject: [PATCH 36/36] Disable unreleased host ui url --- cmd/btfs/daemon.go | 4 ++-- cmd/ipfswatch/main.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/btfs/daemon.go b/cmd/btfs/daemon.go index 3d6d78eb7..186b24109 100644 --- a/cmd/btfs/daemon.go +++ b/cmd/btfs/daemon.go @@ -549,7 +549,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error apiMaddr = apiLis.Multiaddr() fmt.Printf("API server listening on %s\n", apiMaddr) fmt.Printf("WebUI: http://%s/webui\n", apiLis.Addr()) - fmt.Printf("HostUI: http://%s/hostui\n", apiLis.Addr()) + //fmt.Printf("HostUI: http://%s/hostui\n", apiLis.Addr()) listeners = append(listeners, apiLis) } @@ -568,7 +568,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error corehttp.CheckVersionOption(), corehttp.CommandsOption(*cctx), corehttp.WebUIOption, - corehttp.HostUIOption, + //corehttp.HostUIOption, gatewayOpt, corehttp.VersionOption(), defaultMux("/debug/vars"), diff --git a/cmd/ipfswatch/main.go b/cmd/ipfswatch/main.go index 573fc5bb8..5a5d9d4a6 100644 --- a/cmd/ipfswatch/main.go +++ b/cmd/ipfswatch/main.go @@ -94,7 +94,7 @@ func run(ipfsPath, watchPath string) error { var opts = []corehttp.ServeOption{ corehttp.GatewayOption(true, "/btfs", "/btns"), corehttp.WebUIOption, - corehttp.HostUIOption, + //corehttp.HostUIOption, corehttp.CommandsOption(cmdCtx(node, ipfsPath)), } proc.Go(func(p process.Process) {