From e51e397f47463b3db04f1de8613e15f0924c02d1 Mon Sep 17 00:00:00 2001 From: Erin Rivas Date: Wed, 1 Nov 2023 15:51:34 -0500 Subject: [PATCH] updates to folder nesting mostly --- handlers/file_io_handler/txs.go | 66 ++++++++++++++++++++++++++++++++ handlers/folder_handler/types.go | 18 ++++++--- handlers/wallet_handler/txs.go | 2 +- handlers/wallet_handler/types.go | 16 ++------ 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/handlers/file_io_handler/txs.go b/handlers/file_io_handler/txs.go index b62ce8b..56cbe75 100644 --- a/handlers/file_io_handler/txs.go +++ b/handlers/file_io_handler/txs.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/JackalLabs/jackalgo/handlers/storage_handler" "github.com/JackalLabs/jackalgo/utils" + "strings" "time" "github.com/JackalLabs/jackalgo/handlers/file_upload_handler" @@ -20,6 +21,69 @@ import ( storagetypes "github.com/jackalLabs/canine-chain/v3/x/storage/types" ) +func (f *FileIoHandler) SignAndBroadcast(msgs []sdk.Msg) error { + res, err := f.walletHandler.SendTx(msgs...) + if err != nil { + return err + } + fmt.Println(res.Code) + fmt.Println(res.RawLog) + return nil +} + +func (f *FileIoHandler) LoadNestedFolder(rawPath string) (folderHandlers *folder_handler.FolderHandler, msgs []sdk.Msg, err error) { + folders := folder_handler.FolderGroup{} + msgs = []sdk.Msg{} + pathChunks := strings.Split(rawPath, "/") + + for i := 1; i < len(pathChunks); i++ { + parentSubString := strings.Join(pathChunks[0:i], "/") + subString := strings.Join(pathChunks[0:i+1], "/") + + fmt.Println("cycle start") + fmt.Println(parentSubString) + fmt.Println(subString) + + rawSubFolder, err := compression.ReadFileTreeEntry(f.walletHandler.GetAddress(), subString, f.walletHandler) + fmt.Println(rawSubFolder) + fmt.Println(err) + fmt.Println(pathChunks[i]) + if err != nil { + folders[subString] = folder_handler.TrackNewFolder( + pathChunks[i], + parentSubString, + folders[parentSubString].GetWhoOwnsMe(), + f.walletHandler, + ) + + fmt.Println(folders[subString].GetFolderDetails()) + + msg, _, err := folders[parentSubString].AddChildDirs([]string{pathChunks[i]}) + fmt.Println(folders[parentSubString].GetChildDirs()) + fmt.Println(msg) + fmt.Println(err) + if err != nil { + return nil, nil, err + } + + msgs = append(msgs, msg...) + } else { + var subFrame folder_handler.FolderFileFrame + err = json.Unmarshal(rawSubFolder, &subFrame) + if err != nil { + return nil, nil, err + } + + folders[subString] = folder_handler.TrackFolder(subFrame, f.walletHandler) + } + fmt.Println("msgs") + fmt.Println(msgs) + } + fmt.Println("LoadNestedFolder done") + + return folders[rawPath], msgs, err +} + func (f *FileIoHandler) CreateFolders(parentDir *folder_handler.FolderHandler, newDirs []string) (msgs []sdk.Msg, err error) { msgs, existing, err := parentDir.AddChildDirs(newDirs) if err != nil { @@ -96,6 +160,8 @@ func (f *FileIoHandler) GenerateInitialDirs(startingDirs []string) (*sdk.TxRespo dirMsgs[i] = msg } + //fmt.Println(dirMsgs) + readyToBroadcast := make([]sdk.Msg, 0) pubKeyQuerier := filetreetypes.NewQueryClient(f.walletHandler.GetClientCtx()) diff --git a/handlers/folder_handler/types.go b/handlers/folder_handler/types.go index f5b49d9..e2e2f2a 100644 --- a/handlers/folder_handler/types.go +++ b/handlers/folder_handler/types.go @@ -16,6 +16,8 @@ type FolderHandler struct { walletHandler *wallet_handler.WalletHandler } +type FolderGroup map[string]*FolderHandler + func NewFolderHandler(frame FolderFileFrame, wallet *wallet_handler.WalletHandler) *FolderHandler { r := FolderHandler{ folderDetails: frame, @@ -86,14 +88,18 @@ func (f *FolderHandler) AddChildDirs(childNames []string) ([]sdk.Msg, []string, existing := make([]string, 0) more := make([]string, 0) - for _, name := range childNames { - for _, childDir := range f.folderDetails.DirChildren { - if name == childDir { - existing = append(existing, name) - continue + if len(f.folderDetails.DirChildren) > 0 { + for _, name := range childNames { + for _, childDir := range f.folderDetails.DirChildren { + if name == childDir { + existing = append(existing, name) + continue + } + more = append(more, name) } - more = append(more, name) } + } else { + more = append(more, childNames...) } msgs := make([]sdk.Msg, len(more)) diff --git a/handlers/wallet_handler/txs.go b/handlers/wallet_handler/txs.go index 5fcaabc..f927fdd 100644 --- a/handlers/wallet_handler/txs.go +++ b/handlers/wallet_handler/txs.go @@ -20,7 +20,7 @@ func AddTxFlags(set *pflag.FlagSet) { set.String(flags.FlagGasPrices, "0.002ujkl", "Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)") set.String(flags.FlagNode, "tcp://localhost:26657", ": to tendermint rpc interface for this chain") set.Bool(flags.FlagUseLedger, false, "Use a connected Ledger device") - set.Float64(flags.FlagGasAdjustment, flags.DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") + //set.Float64(flags.FlagGasAdjustment, flags.DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") set.StringP(flags.FlagBroadcastMode, "b", flags.BroadcastBlock, "Transaction broadcasting mode (sync|async|block)") set.Bool(flags.FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)") set.Bool(flags.FlagGenerateOnly, false, "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase is not accessible)") diff --git a/handlers/wallet_handler/types.go b/handlers/wallet_handler/types.go index 0e5da0d..cb5cb48 100644 --- a/handlers/wallet_handler/types.go +++ b/handlers/wallet_handler/types.go @@ -85,17 +85,6 @@ func NewWalletHandler(seedPhrase string, rpc string, chainId string) (*WalletHan // if found address := sdk.AccAddress(pKey.PubKey().Address()) - //var pKey *cryptotypes.PrivKey = nil - //address := "" - //if len(seedPhrase) > 0 { - // pKey = cryptotypes.GenPrivKeyFromSecret([]byte(seedPhrase)) - // var err error - // address, err = bech32.ConvertAndEncode(Bech32PrefixAccAddr, pKey.PubKey().Address().Bytes()) - // if err != nil { - // return nil, err - // } - //} - cl, err := client.NewClientFromNode(rpc) if err != nil { return nil, err @@ -121,11 +110,12 @@ func NewWalletHandler(seedPhrase string, rpc string, chainId string) (*WalletHan eciesKey := ecies.NewPrivateKeyFromBytes(newpkey[:32]) - flags := createFlags("auto", address.String()) + flgs := createFlags("auto", address.String()) + flgs.Float64(flags.FlagGasAdjustment, 1.5, fmt.Sprintf("the gas adjustment, the default is %f", 1.5)) w := WalletHandler{ clientCtx: clientCtx, - flags: flags, + flags: flgs, key: pKey, address: address.String(), eciesKey: eciesKey,