Skip to content

Commit

Permalink
updates to folder nesting mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Nov 1, 2023
1 parent c101236 commit e51e397
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 20 deletions.
66 changes: 66 additions & 0 deletions handlers/file_io_handler/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
18 changes: 12 additions & 6 deletions handlers/folder_handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion handlers/wallet_handler/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<host>:<port> 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)")
Expand Down
16 changes: 3 additions & 13 deletions handlers/wallet_handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit e51e397

Please sign in to comment.