From 6c6f8fd6ec60d1c0db8323955ab347de919abe17 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 25 Oct 2023 15:44:02 -0500 Subject: [PATCH 01/18] update to add generate flix command --- internal/super/flix.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/internal/super/flix.go b/internal/super/flix.go index ebbc33124..29d30b152 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -84,9 +84,21 @@ var bindingCommand = &command.Command{ RunS: bindingsCmd, } +var generateCommand = &command.Command{ + Cmd: &cobra.Command{ + Use: "generate cadence.cdc", + Short: "generate FLIX json template given local filename", + Example: "flow flix generate multiply.cdc", + Args: cobra.MinimumNArgs(1), + }, + Flags: &flags, + RunS: generateCmd, +} + func init() { executeCommand.AddToParent(FlixCmd) bindingCommand.AddToParent(FlixCmd) + generateCommand.AddToParent(FlixCmd) } type flixQueryTypes string @@ -193,6 +205,36 @@ func bindingsCmd( }, err } +func generateCmd( + args []string, + _ command.GlobalFlags, + logger output.Logger, + flow flowkit.Services, + state *flowkit.State, +) (result command.Result, err error) { + cadenceFile := args[0] + + if cadenceFile == "" { + return nil, fmt.Errorf("no cadence code found") + } + + code, err := state.ReadFile(cadenceFile) + if err != nil { + return nil, fmt.Errorf("could not read cadence file %s: %w", cadenceFile, err) + } + + flixGen := generator.Generator1_0_0() + flix, err := flixGen.Generate(code) + if err != nil { + return nil, fmt.Errorf("could not generate flix %w", err) + } + + return &flixResult{ + flixQuery: cadenceFile, + result: flix, + }, err +} + func (fr *flixResult) JSON() any { result := make(map[string]any) result["flixQuery"] = fr.flixQuery From 719f30167eac65cc118c880075bd0a4386b30d92 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 25 Oct 2023 23:00:53 -0500 Subject: [PATCH 02/18] add generate flix cmd --- internal/super/flix.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 29d30b152..118ec6279 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -21,11 +21,13 @@ package super import ( "context" "encoding/hex" + "encoding/json" "fmt" "os" "github.com/onflow/flixkit-go" "github.com/onflow/flixkit-go/bindings" + "github.com/onflow/flixkit-go/generator" "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/output" @@ -223,15 +225,17 @@ func generateCmd( return nil, fmt.Errorf("could not read cadence file %s: %w", cadenceFile, err) } - flixGen := generator.Generator1_0_0() - flix, err := flixGen.Generate(code) + flix, err := generator.NewGenerator().Generate(string(code)) if err != nil { return nil, fmt.Errorf("could not generate flix %w", err) } - + prettyJSON, err := json.MarshalIndent(flix, "", " ") + if err != nil { + return nil, fmt.Errorf("could not marshal flix %w", err) + } return &flixResult{ flixQuery: cadenceFile, - result: flix, + result: string(prettyJSON), }, err } From 762cfa14d6b93e74f499dbb3efff5916c902ecc1 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 25 Oct 2023 23:05:55 -0500 Subject: [PATCH 03/18] testing locally generate template --- go.mod | 24 ++++++++++++---------- go.sum | 46 ++++++++++++++++++++++-------------------- internal/super/flix.go | 45 +++++++++++++++++++++-------------------- 3 files changed, 60 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index 687e78785..7d267bb63 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/bits-and-blooms/bitset v1.5.0 // indirect + github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect github.com/c-bata/go-prompt v0.2.6 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect @@ -57,7 +57,7 @@ require ( github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/coreos/go-semver v0.3.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect @@ -88,7 +88,7 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-dap v0.10.0 // indirect github.com/google/go-github v17.0.0+incompatible // indirect github.com/google/go-querystring v1.1.0 // indirect @@ -143,7 +143,7 @@ require ( github.com/logrusorgru/aurora/v4 v4.0.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mattn/go-tty v0.0.4 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect @@ -177,7 +177,7 @@ require ( github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/term v1.2.0-beta.2 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.42.0 // indirect @@ -185,7 +185,7 @@ require ( github.com/psiemens/graceland v1.0.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rivo/uniseg v0.4.4 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/cors v1.8.0 // indirect github.com/rs/zerolog v1.29.0 // indirect github.com/schollz/progressbar/v3 v3.13.1 // indirect @@ -222,15 +222,15 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.11.0 // indirect + golang.org/x/crypto v0.14.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.10.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.12.0 // indirect - golang.org/x/term v0.10.0 // indirect - golang.org/x/text v0.11.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gonum.org/v1/gonum v0.13.0 // indirect google.golang.org/api v0.126.0 // indirect google.golang.org/appengine v1.6.7 // indirect @@ -250,3 +250,5 @@ require ( ) replace github.com/onflow/flow-cli/flowkit => ./flowkit + +replace github.com/onflow/flixkit-go => /Users/tomhaile/gitrepos/flixkit-go diff --git a/go.sum b/go.sum index d10c8697a..c0868e60e 100644 --- a/go.sum +++ b/go.sum @@ -142,8 +142,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bits-and-blooms/bitset v1.5.0 h1:NpE8frKRLGHIcEzkR+gZhiioW1+WbYV6fKwD6ZIpQT8= -github.com/bits-and-blooms/bitset v1.5.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= +github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= @@ -235,8 +235,9 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -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/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= @@ -467,8 +468,9 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-dap v0.10.0 h1:H6ndTbkoEVpOk9gqSerFiqgCNZ8zYFpsyfmq1GuB+Tc= github.com/google/go-dap v0.10.0/go.mod h1:HAeyoSd2WIfTfg+0GRXcFrb+RnojAtGNh+k+XTIxJDE= github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= @@ -779,8 +781,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -894,8 +896,6 @@ github.com/onflow/cadence-tools/test v0.13.0 h1:K94h3EiPnwS1iWmvCjqO6cgArOGdPp+5 github.com/onflow/cadence-tools/test v0.13.0/go.mod h1:Xb/S5oP4WKoJQ2RUKXDNSW41hYtQBUpgdcWggn6S2t4= github.com/onflow/fcl-dev-wallet v0.7.4 h1:vI6t3U0AO88R/Iitn5KsnniSpbN9Lqsqwvi9EJT4C0k= github.com/onflow/fcl-dev-wallet v0.7.4/go.mod h1:kc42jkiuoPJmxMRFjfbRO9XvnR/3XLheaOerxVMDTiw= -github.com/onflow/flixkit-go v0.2.0 h1:yI7jksFPkLoQkFZ31oYrq3xPaZBn+qqLslpLM7TttSo= -github.com/onflow/flixkit-go v0.2.0/go.mod h1:i3EYZbxDP+k0n4nt1fzlwBFMENdNA82w+ZlQ9knfunQ= github.com/onflow/flow-archive v1.3.4-0.20230503192214-9e81e82d4dcc h1:C4ZniFeOv+pHlDLJdGc/4e3NklSjVuvaXKN47980gnY= github.com/onflow/flow-archive v1.3.4-0.20230503192214-9e81e82d4dcc/go.mod h1:UPsvKk/37Atosif4wlBl3gsLbGJyGpdXYpXDsWtMVBE= github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20230703193002-53362441b57d h1:B7PdhdUNkve5MVrekWDuQf84XsGBxNZ/D3x+QQ8XeVs= @@ -978,8 +978,9 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw= github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -1043,8 +1044,9 @@ github.com/robertkrimen/otto v0.0.0-20170205013659-6a77b7cbc37d/go.mod h1:xvqspo github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.0 h1:P2KMzcFwrPoSjkF1WLRPsp3UMLyql8L4v9hQpVeK5so= @@ -1288,8 +1290,8 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1334,7 +1336,7 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1521,8 +1523,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1530,8 +1532,8 @@ golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= -golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1544,8 +1546,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1622,13 +1624,13 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.6.1/go.mod h1:9mxDZsDKxgMAuccQkewq682L+0eCu4dCN2yonUJTCLU= gonum.org/v1/gonum v0.13.0 h1:a0T3bh+7fhRyqeNbiC3qVHYmkiQgit3wnNan/2c0HMM= diff --git a/internal/super/flix.go b/internal/super/flix.go index 118ec6279..3cc4b1160 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -21,13 +21,11 @@ package super import ( "context" "encoding/hex" - "encoding/json" "fmt" "os" "github.com/onflow/flixkit-go" "github.com/onflow/flixkit-go/bindings" - "github.com/onflow/flixkit-go/generator" "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/output" @@ -214,29 +212,32 @@ func generateCmd( flow flowkit.Services, state *flowkit.State, ) (result command.Result, err error) { - cadenceFile := args[0] + /* + cadenceFile := args[0] - if cadenceFile == "" { - return nil, fmt.Errorf("no cadence code found") - } + if cadenceFile == "" { + return nil, fmt.Errorf("no cadence code found") + } - code, err := state.ReadFile(cadenceFile) - if err != nil { - return nil, fmt.Errorf("could not read cadence file %s: %w", cadenceFile, err) - } + code, err := state.ReadFile(cadenceFile) + if err != nil { + return nil, fmt.Errorf("could not read cadence file %s: %w", cadenceFile, err) + } - flix, err := generator.NewGenerator().Generate(string(code)) - if err != nil { - return nil, fmt.Errorf("could not generate flix %w", err) - } - prettyJSON, err := json.MarshalIndent(flix, "", " ") - if err != nil { - return nil, fmt.Errorf("could not marshal flix %w", err) - } - return &flixResult{ - flixQuery: cadenceFile, - result: string(prettyJSON), - }, err + flix, err := generator.NewGenerator().Generate(string(code)) + if err != nil { + return nil, fmt.Errorf("could not generate flix %w", err) + } + prettyJSON, err := json.MarshalIndent(flix, "", " ") + if err != nil { + return nil, fmt.Errorf("could not marshal flix %w", err) + } + return &flixResult{ + flixQuery: cadenceFile, + result: string(prettyJSON), + }, err + */ + return nil, nil } func (fr *flixResult) JSON() any { From 0b9010dd1502771bf1b7a8562a4a974e3dcb767c Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 31 Oct 2023 15:05:27 -0500 Subject: [PATCH 04/18] integrate new 1.0.0 generate tempalte into existing flix command --- internal/super/flix.go | 109 +++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 31 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 3cc4b1160..03392aa59 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -21,13 +21,17 @@ package super import ( "context" "encoding/hex" + "encoding/json" "fmt" "os" + "path/filepath" "github.com/onflow/flixkit-go" "github.com/onflow/flixkit-go/bindings" + "github.com/onflow/flixkit-go/generator" "github.com/onflow/flow-cli/flowkit" + "github.com/onflow/flow-cli/flowkit/config" "github.com/onflow/flow-cli/flowkit/output" "github.com/onflow/flow-cli/internal/command" "github.com/onflow/flow-cli/internal/scripts" @@ -57,7 +61,7 @@ type flixResult struct { var flags = flixFlags{} var FlixCmd = &cobra.Command{ Use: "flix", - Short: "execute, bindings", + Short: "execute, package", TraverseChildren: true, GroupID: "tools", } @@ -75,13 +79,13 @@ var executeCommand = &command.Command{ var bindingCommand = &command.Command{ Cmd: &cobra.Command{ - Use: "bindings ", - Short: "generate binding file for FLIX template fcl-js is default", - Example: "flow flix bindings multiply.template.json", + Use: "package ", + Short: "package file for FLIX template fcl-js is default", + Example: "flow flix package multiply.template.json", Args: cobra.MinimumNArgs(1), }, Flags: &flags, - RunS: bindingsCmd, + RunS: packageCmd, } var generateCommand = &command.Command{ @@ -175,9 +179,9 @@ func executeCmd( return transactions.SendTransaction([]byte(cadenceWithImportsReplaced), args[1:], "", flow, state, transactionFlags) } -func bindingsCmd( +func packageCmd( args []string, - _ command.GlobalFlags, + flags command.GlobalFlags, logger output.Logger, flow flowkit.Services, state *flowkit.State, @@ -185,19 +189,25 @@ func bindingsCmd( flixService := flixkit.NewFlixService(&flixkit.Config{}) flixQuery := args[0] + fmt.Println("flixQuery", flixQuery) template, err := getTemplate(state, flixService, flixQuery) if err != nil { return nil, err } - isLocal := false if getType(flixQuery) == flixPath { - isLocal = true + if flags.Save != "" { + // resolve template file location to relative path to be used by binding file + flixQuery, err = GetRelativePath(flixQuery, flags.Save) + if err != nil { + logger.Error("could not resolve relative path to template") + return nil, err + } + } } fclJsGen := bindings.NewFclJSGenerator() - - out, err := fclJsGen.Generate(template, flixQuery, isLocal) + out, err := fclJsGen.Generate(template, flixQuery, isPath(flixQuery)) return &flixResult{ flixQuery: flixQuery, @@ -212,32 +222,54 @@ func generateCmd( flow flowkit.Services, state *flowkit.State, ) (result command.Result, err error) { - /* - cadenceFile := args[0] - if cadenceFile == "" { - return nil, fmt.Errorf("no cadence code found") - } + cadenceFile := args[0] - code, err := state.ReadFile(cadenceFile) - if err != nil { - return nil, fmt.Errorf("could not read cadence file %s: %w", cadenceFile, err) - } + if cadenceFile == "" { + return nil, fmt.Errorf("no cadence code found") + } - flix, err := generator.NewGenerator().Generate(string(code)) + code, err := state.ReadFile(cadenceFile) + if err != nil { + return nil, fmt.Errorf("could not read cadence file %s: %w", cadenceFile, err) + } + + depContracts := make([]flixkit.Contracts, 0) + for _, deployment := range *state.Deployments() { + contracts, err := state.DeploymentContractsByNetwork(config.Network{Name: deployment.Network}) if err != nil { - return nil, fmt.Errorf("could not generate flix %w", err) + continue } - prettyJSON, err := json.MarshalIndent(flix, "", " ") - if err != nil { - return nil, fmt.Errorf("could not marshal flix %w", err) + for _, contract := range contracts { + contract := flixkit.Contracts{ + contract.Name: flixkit.Networks{ + deployment.Network: flixkit.Network{ + Address: "0x" + contract.AccountAddress.String(), + FqAddress: "A." + contract.AccountAddress.String() + "." + contract.Name, + Contract: contract.Name, + }, + }, + } + depContracts = append(depContracts, contract) } - return &flixResult{ - flixQuery: cadenceFile, - result: string(prettyJSON), - }, err - */ - return nil, nil + } + + gen_1_0_0 := generator.NewGenerator(depContracts) + flix, err := gen_1_0_0.Generate(string(code)) + if err != nil { + return nil, fmt.Errorf("could not generate flix %w", err) + } + + prettyJSON, err := json.MarshalIndent(flix, "", " ") + if err != nil { + return nil, fmt.Errorf("could not marshal flix %w", err) + } + + return &flixResult{ + flixQuery: cadenceFile, + result: string(prettyJSON), + }, err + } func (fr *flixResult) JSON() any { @@ -287,3 +319,18 @@ func getTemplate(state *flowkit.State, flixService flixkit.FlixService, flixQuer } return template, nil } + +// GetRelativePath computes the relative path from target to source. +func GetRelativePath(source, target string) (string, error) { + relPath, err := filepath.Rel(filepath.Dir(target), source) + if err != nil { + return "", err + } + + // If the file is in the same directory and doesn't start with "./", prepend it. + if !filepath.IsAbs(relPath) && relPath[0] != '.' { + relPath = "./" + relPath + } + + return relPath, nil +} From ec07e7c7b5418a8df688d2c588e5f7ce760dfcea Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 7 Nov 2023 12:05:16 -0600 Subject: [PATCH 05/18] add generate flix 1.0.0 to flix command --- internal/super/flix.go | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 03392aa59..f2df23e0b 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -189,7 +189,6 @@ func packageCmd( flixService := flixkit.NewFlixService(&flixkit.Config{}) flixQuery := args[0] - fmt.Println("flixQuery", flixQuery) template, err := getTemplate(state, flixService, flixQuery) if err != nil { return nil, err @@ -222,7 +221,6 @@ func generateCmd( flow flowkit.Services, state *flowkit.State, ) (result command.Result, err error) { - cadenceFile := args[0] if cadenceFile == "" { @@ -234,28 +232,14 @@ func generateCmd( return nil, fmt.Errorf("could not read cadence file %s: %w", cadenceFile, err) } - depContracts := make([]flixkit.Contracts, 0) - for _, deployment := range *state.Deployments() { - contracts, err := state.DeploymentContractsByNetwork(config.Network{Name: deployment.Network}) - if err != nil { - continue - } - for _, contract := range contracts { - contract := flixkit.Contracts{ - contract.Name: flixkit.Networks{ - deployment.Network: flixkit.Network{ - Address: "0x" + contract.AccountAddress.String(), - FqAddress: "A." + contract.AccountAddress.String() + "." + contract.Name, - Contract: contract.Name, - }, - }, - } - depContracts = append(depContracts, contract) - } + depContracts := GetDeployedContracts(state) + gen_1_0_0, err := generator.NewGenerator(depContracts, nil, logger) + if err != nil { + return nil, fmt.Errorf("could not create flix generator %w", err) } - gen_1_0_0 := generator.NewGenerator(depContracts) - flix, err := gen_1_0_0.Generate(string(code)) + ctx := context.Background() + flix, err := gen_1_0_0.Generate(ctx, string(code)) if err != nil { return nil, fmt.Errorf("could not generate flix %w", err) } @@ -334,3 +318,26 @@ func GetRelativePath(source, target string) (string, error) { return relPath, nil } + +func GetDeployedContracts(state *flowkit.State) []flixkit.Contracts { + depContracts := make([]flixkit.Contracts, 0) + for _, deployment := range *state.Deployments() { + contracts, err := state.DeploymentContractsByNetwork(config.Network{Name: deployment.Network}) + if err != nil { + continue + } + for _, contract := range contracts { + contract := flixkit.Contracts{ + contract.Name: flixkit.Networks{ + deployment.Network: flixkit.Network{ + Address: "0x" + contract.AccountAddress.String(), + FqAddress: "A." + contract.AccountAddress.String() + "." + contract.Name, + Contract: contract.Name, + }, + }, + } + depContracts = append(depContracts, contract) + } + } + return depContracts +} From ab2b28ebd8bfdf6a118a58b7eae4e3cb49e89cd6 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 7 Nov 2023 12:06:31 -0600 Subject: [PATCH 06/18] add generate to high level flix command help --- internal/super/flix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index f2df23e0b..d5b893ab9 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -61,7 +61,7 @@ type flixResult struct { var flags = flixFlags{} var FlixCmd = &cobra.Command{ Use: "flix", - Short: "execute, package", + Short: "execute, generate, package", TraverseChildren: true, GroupID: "tools", } From d93ec2c47ef7cf3b787431eaf9bc4f2b7ff379e6 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 7 Nov 2023 15:07:10 -0600 Subject: [PATCH 07/18] add ability to get flix via url --- internal/super/flix.go | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index d5b893ab9..f341c0455 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -23,6 +23,9 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io" + "net/http" + "net/url" "os" "path/filepath" @@ -68,8 +71,8 @@ var FlixCmd = &cobra.Command{ var executeCommand = &command.Command{ Cmd: &cobra.Command{ - Use: "execute ", - Short: "execute FLIX template with a given id, name, or local filename", + Use: "execute ", + Short: "execute FLIX template with a given id, name, local filename, or url", Example: "flow flix execute transfer-flow 1 0x123456789", Args: cobra.MinimumNArgs(1), }, @@ -79,7 +82,7 @@ var executeCommand = &command.Command{ var bindingCommand = &command.Command{ Cmd: &cobra.Command{ - Use: "package ", + Use: "package ", Short: "package file for FLIX template fcl-js is default", Example: "flow flix package multiply.template.json", Args: cobra.MinimumNArgs(1), @@ -111,6 +114,7 @@ const ( flixName flixQueryTypes = "name" flixPath flixQueryTypes = "path" flixId flixQueryTypes = "id" + flixUrl flixQueryTypes = "url" ) func isHex(str string) bool { @@ -126,12 +130,19 @@ func isPath(path string) bool { return err == nil } +func isUrl(str string) bool { + u, err := url.Parse(str) + return err == nil && u.Scheme != "" && u.Host != "" +} + func getType(s string) flixQueryTypes { switch { case isPath(s): return flixPath case isHex(s): return flixId + case isUrl(s): + return flixUrl default: return flixName } @@ -297,6 +308,26 @@ func getTemplate(state *flowkit.State, flixService flixkit.FlixService, flixQuer if err != nil { return nil, fmt.Errorf("could not parse flix from file %s: %w", flixQuery, err) } + case flixUrl: + resp, err := http.Get(flixQuery) + if err != nil { + return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("server returned non-200 status code %w", resp.StatusCode) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + template, err = flixkit.ParseFlix(string(body)) + if err != nil { + return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err) + } default: return nil, fmt.Errorf("invalid flix query type: %s", flixQuery) From 08c9c90692e8a5842246389c7f03d111c9a40fd9 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 8 Nov 2023 11:00:03 -0600 Subject: [PATCH 08/18] allow user to pass in a pre-fill flix template json file instead of relying on cadence comment block --- internal/super/flix.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index f341c0455..8a3ae1168 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -31,7 +31,7 @@ import ( "github.com/onflow/flixkit-go" "github.com/onflow/flixkit-go/bindings" - "github.com/onflow/flixkit-go/generator" + "github.com/onflow/flixkit-go/generator/v1_0_0" "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/config" @@ -54,6 +54,7 @@ type flixFlags struct { Include []string `default:"" flag:"include" info:"Fields to include in the output"` Exclude []string `default:"" flag:"exclude" info:"Fields to exclude from the output (events)"` GasLimit uint64 `default:"1000" flag:"gas-limit" info:"transaction gas limit"` + PreFill string `default:"" flag:"pre-fill" info:"template path to pre fill the FLIX"` } type flixResult struct { @@ -94,7 +95,7 @@ var bindingCommand = &command.Command{ var generateCommand = &command.Command{ Cmd: &cobra.Command{ Use: "generate cadence.cdc", - Short: "generate FLIX json template given local filename", + Short: "generate FLIX json template given local Cadence filename", Example: "flow flix generate multiply.cdc", Args: cobra.MinimumNArgs(1), }, @@ -244,13 +245,21 @@ func generateCmd( } depContracts := GetDeployedContracts(state) - gen_1_0_0, err := generator.NewGenerator(depContracts, nil, logger) + gen_1_0_0, err := v1_0_0.NewGenerator(depContracts, nil, logger) if err != nil { return nil, fmt.Errorf("could not create flix generator %w", err) } + var template *flixkit.FlowInteractionTemplate + if flags.PreFill != "" { + flixService := flixkit.NewFlixService(&flixkit.Config{}) + template, err = getTemplate(state, flixService, flags.PreFill) + if err != nil { + return nil, fmt.Errorf("could not parse template from pre fill %w", err) + } + } ctx := context.Background() - flix, err := gen_1_0_0.Generate(ctx, string(code)) + flix, err := gen_1_0_0.Generate(ctx, string(code), template) if err != nil { return nil, fmt.Errorf("could not generate flix %w", err) } From fc6b3bae30566d772bf735315fddffd1f0d630d8 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 8 Nov 2023 12:36:32 -0600 Subject: [PATCH 09/18] use 1_0_0 generator version and Generator interface --- internal/super/flix.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 8a3ae1168..877cb2645 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -245,7 +245,7 @@ func generateCmd( } depContracts := GetDeployedContracts(state) - gen_1_0_0, err := v1_0_0.NewGenerator(depContracts, nil, logger) + generator, err := v1_0_0.NewGenerator(depContracts, nil, logger) if err != nil { return nil, fmt.Errorf("could not create flix generator %w", err) } @@ -259,7 +259,7 @@ func generateCmd( } } ctx := context.Background() - flix, err := gen_1_0_0.Generate(ctx, string(code), template) + flix, err := generator.Generate(ctx, string(code), template) if err != nil { return nil, fmt.Errorf("could not generate flix %w", err) } From 2a8ae0d822454eaa2612c1ee7589ff9af7654de1 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 8 Nov 2023 15:33:17 -0600 Subject: [PATCH 10/18] fix issue where relative path is interpreted as url --- internal/super/flix.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 877cb2645..9fcb2b3d1 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -205,8 +205,9 @@ func packageCmd( if err != nil { return nil, err } - + isLocal := false if getType(flixQuery) == flixPath { + isLocal = true if flags.Save != "" { // resolve template file location to relative path to be used by binding file flixQuery, err = GetRelativePath(flixQuery, flags.Save) @@ -218,7 +219,7 @@ func packageCmd( } fclJsGen := bindings.NewFclJSGenerator() - out, err := fclJsGen.Generate(template, flixQuery, isPath(flixQuery)) + out, err := fclJsGen.Generate(template, flixQuery, isLocal) return &flixResult{ flixQuery: flixQuery, From 54ad5a23d1168d44820a8ff47e04f126091fec60 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 14 Nov 2023 15:25:57 -0600 Subject: [PATCH 11/18] update to use new module name for generate flix --- internal/super/flix.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 9fcb2b3d1..40cea8d51 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -31,7 +31,7 @@ import ( "github.com/onflow/flixkit-go" "github.com/onflow/flixkit-go/bindings" - "github.com/onflow/flixkit-go/generator/v1_0_0" + "github.com/onflow/flixkit-go/generator/flixkitv1_0_0" "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/config" @@ -246,7 +246,7 @@ func generateCmd( } depContracts := GetDeployedContracts(state) - generator, err := v1_0_0.NewGenerator(depContracts, nil, logger) + generator, err := flixkitv1_0_0.NewGenerator(depContracts, nil, logger) if err != nil { return nil, fmt.Errorf("could not create flix generator %w", err) } From 2763bab871def57078272e31c6303b91f16236bc Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 20 Nov 2023 10:56:35 -0700 Subject: [PATCH 12/18] update to use newest version of flixkit-go --- go.mod | 14 +++++++------- go.sum | 24 +++++++++++------------- internal/super/flix.go | 4 ++-- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 74e8ba320..6459212d6 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/onflow/cadence-tools/languageserver v0.33.1 github.com/onflow/cadence-tools/test v0.14.1 github.com/onflow/fcl-dev-wallet v0.7.4 - github.com/onflow/flixkit-go v0.2.0 + github.com/onflow/flixkit-go v0.3.0 github.com/onflow/flow-cli/flowkit v1.6.1-0.20231110211255-b41f57a8b8c7 github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f github.com/onflow/flow-emulator v0.57.3 @@ -45,7 +45,7 @@ require ( github.com/VictoriaMetrics/fastcache v1.6.0 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/bits-and-blooms/bitset v1.7.0 // indirect + github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect github.com/c-bata/go-prompt v0.2.6 // indirect @@ -60,7 +60,7 @@ require ( github.com/cockroachdb/redact v1.1.3 // indirect github.com/coreos/go-semver v0.3.0 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect @@ -235,16 +235,16 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.14.0 // indirect - golang.org/x/mod v0.12.0 // indirect + golang.org/x/mod v0.13.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.11.0 // indirect - golang.org/x/sync v0.3.0 // indirect + golang.org/x/sync v0.4.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.13.0 // indirect - golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect + golang.org/x/tools v0.14.0 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gonum.org/v1/gonum v0.13.0 // indirect google.golang.org/api v0.126.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 45bf5e2aa..92baa600a 100644 --- a/go.sum +++ b/go.sum @@ -144,8 +144,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= -github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= +github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd/btcec/v2 v2.2.1 h1:xP60mv8fvp+0khmrN0zTdPC3cNm24rfeE6lh2R/Yv3E= @@ -473,7 +473,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-dap v0.11.0 h1:SpAZJL41rOOvd85PuLCCLE1dteTQOyKNnn0H3DBHywo= github.com/google/go-dap v0.11.0/go.mod h1:HAeyoSd2WIfTfg+0GRXcFrb+RnojAtGNh+k+XTIxJDE= github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= @@ -897,6 +897,8 @@ github.com/onflow/cadence-tools/test v0.14.1 h1:QWYslLEwh+gmJHblK6DUyZnpOo6L6U6x github.com/onflow/cadence-tools/test v0.14.1/go.mod h1:c/kyFSaBso7SW5eki1cFmP0/A+H3y/ctO95zJedcf+Q= github.com/onflow/fcl-dev-wallet v0.7.4 h1:vI6t3U0AO88R/Iitn5KsnniSpbN9Lqsqwvi9EJT4C0k= github.com/onflow/fcl-dev-wallet v0.7.4/go.mod h1:kc42jkiuoPJmxMRFjfbRO9XvnR/3XLheaOerxVMDTiw= +github.com/onflow/flixkit-go v0.3.0 h1:kVp8pjTds+K7PniLtKFtIL8q7LSZxTmFbb7qVQ6rkag= +github.com/onflow/flixkit-go v0.3.0/go.mod h1:H+x/JnydsqM1jmn927RTsyjSZtFFPloJUfY3zE8kMik= github.com/onflow/flow-archive v1.3.4-0.20230503192214-9e81e82d4dcc h1:C4ZniFeOv+pHlDLJdGc/4e3NklSjVuvaXKN47980gnY= github.com/onflow/flow-archive v1.3.4-0.20230503192214-9e81e82d4dcc/go.mod h1:UPsvKk/37Atosif4wlBl3gsLbGJyGpdXYpXDsWtMVBE= github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f h1:S8yIZw9LFXfYD1V5H9BiixihHw3GrXVPrmfplSzYaww= @@ -926,10 +928,6 @@ github.com/onflow/sdks v0.5.0 h1:2HCRibwqDaQ1c9oUApnkZtEAhWiNY2GTpRD5+ftdkN8= github.com/onflow/sdks v0.5.0/go.mod h1:F0dj0EyHC55kknLkeD10js4mo14yTdMotnWMslPirrU= github.com/onflow/wal v0.0.0-20230529184820-bc9f8244608d h1:gAEqYPn3DS83rHIKEpsajnppVD1+zwuYPFyeDVFaQvg= github.com/onflow/wal v0.0.0-20230529184820-bc9f8244608d/go.mod h1:iMC8gkLqu4nkbkAla5HkSBb+FGyQOZiWz3DYm2wSXCk= -github.com/onflowser/flowser/v2 v2.0.14-beta h1:yvmXyGUkR7e0+Z1t7Gyn+p2Q+CpUmgsqF01M7EtNr3k= -github.com/onflowser/flowser/v2 v2.0.14-beta/go.mod h1:g/nfelBOx0A4j60Twsr7GsmKapr2oxtRZQS0lwPHgZY= -github.com/onflowser/flowser/v3 v3.1.2 h1:ctMBVES3o2wG5b/tuYTYtYoxzeH4M6nsmbPoHkUOOEI= -github.com/onflowser/flowser/v3 v3.1.2/go.mod h1:3UZqdIyKVh+wXOhz9p2YrVl+ZvxohxhAmdM68dDKYPE= github.com/onflowser/flowser/v3 v3.1.3 h1:Y8HyQRwhroCWGcV2UPBD+GZDLHTzu2GjdaBoIEn6YAU= github.com/onflowser/flowser/v3 v3.1.3/go.mod h1:3UZqdIyKVh+wXOhz9p2YrVl+ZvxohxhAmdM68dDKYPE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -1348,8 +1346,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1440,8 +1438,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1643,8 +1641,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/super/flix.go b/internal/super/flix.go index 24683f4bf..0a444c9f8 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -66,7 +66,7 @@ var flags = flixFlags{} var FlixCmd = &cobra.Command{ Use: "flix", Short: "execute, generate, package", -] TraverseChildren: true, + TraverseChildren: true, GroupID: "tools", } @@ -105,7 +105,7 @@ var generateCommand = &command.Command{ func init() { executeCommand.AddToParent(FlixCmd) - bindingCommand.AddToParent(FlixCmd) + packageCommand.AddToParent(FlixCmd) generateCommand.AddToParent(FlixCmd) } From 742416d0e19554f4ecb065df55ff9ec4dec2a6b7 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 20 Nov 2023 13:58:34 -0700 Subject: [PATCH 13/18] use newest fixed version of flixkit-go --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6459212d6..054d0b3be 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/onflow/cadence-tools/languageserver v0.33.1 github.com/onflow/cadence-tools/test v0.14.1 github.com/onflow/fcl-dev-wallet v0.7.4 - github.com/onflow/flixkit-go v0.3.0 + github.com/onflow/flixkit-go v0.3.1 github.com/onflow/flow-cli/flowkit v1.6.1-0.20231110211255-b41f57a8b8c7 github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f github.com/onflow/flow-emulator v0.57.3 diff --git a/go.sum b/go.sum index 92baa600a..087ac5200 100644 --- a/go.sum +++ b/go.sum @@ -897,8 +897,8 @@ github.com/onflow/cadence-tools/test v0.14.1 h1:QWYslLEwh+gmJHblK6DUyZnpOo6L6U6x github.com/onflow/cadence-tools/test v0.14.1/go.mod h1:c/kyFSaBso7SW5eki1cFmP0/A+H3y/ctO95zJedcf+Q= github.com/onflow/fcl-dev-wallet v0.7.4 h1:vI6t3U0AO88R/Iitn5KsnniSpbN9Lqsqwvi9EJT4C0k= github.com/onflow/fcl-dev-wallet v0.7.4/go.mod h1:kc42jkiuoPJmxMRFjfbRO9XvnR/3XLheaOerxVMDTiw= -github.com/onflow/flixkit-go v0.3.0 h1:kVp8pjTds+K7PniLtKFtIL8q7LSZxTmFbb7qVQ6rkag= -github.com/onflow/flixkit-go v0.3.0/go.mod h1:H+x/JnydsqM1jmn927RTsyjSZtFFPloJUfY3zE8kMik= +github.com/onflow/flixkit-go v0.3.1 h1:5izElx+3H7vCqlzK0pzEZ+lW3xjfLoB4w5cD2/3qe2M= +github.com/onflow/flixkit-go v0.3.1/go.mod h1:H+x/JnydsqM1jmn927RTsyjSZtFFPloJUfY3zE8kMik= github.com/onflow/flow-archive v1.3.4-0.20230503192214-9e81e82d4dcc h1:C4ZniFeOv+pHlDLJdGc/4e3NklSjVuvaXKN47980gnY= github.com/onflow/flow-archive v1.3.4-0.20230503192214-9e81e82d4dcc/go.mod h1:UPsvKk/37Atosif4wlBl3gsLbGJyGpdXYpXDsWtMVBE= github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f h1:S8yIZw9LFXfYD1V5H9BiixihHw3GrXVPrmfplSzYaww= From 231038af6680f3e81fb9518c8ea05d7aaf41155d Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 20 Nov 2023 15:20:45 -0700 Subject: [PATCH 14/18] reduce dup code and user flixkit's get flix file given a url --- internal/super/flix.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 0a444c9f8..786955240 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -23,8 +23,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io" - "net/http" "net/url" "os" "path/filepath" @@ -319,22 +317,11 @@ func getTemplate(state *flowkit.State, flixService flixkit.FlixService, flixQuer return nil, fmt.Errorf("could not parse flix from file %s: %w", flixQuery, err) } case flixUrl: - resp, err := http.Get(flixQuery) + flixString, err := flixkit.FetchFlixWithContext(ctx, flixQuery) if err != nil { return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err) } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("server returned non-200 status code %w", resp.StatusCode) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - template, err = flixkit.ParseFlix(string(body)) + template, err = flixkit.ParseFlix(flixString) if err != nil { return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err) } From 28034bf370a10444cefd6d985b223c0cb2d57eee Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 20 Nov 2023 17:54:59 -0700 Subject: [PATCH 15/18] clarify relative path helper method args --- internal/super/flix.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 786955240..a6ba01e50 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -332,9 +332,10 @@ func getTemplate(state *flowkit.State, flixService flixkit.FlixService, flixQuer return template, nil } -// GetRelativePath computes the relative path from target to source. -func GetRelativePath(source, target string) (string, error) { - relPath, err := filepath.Rel(filepath.Dir(target), source) +// GetRelativePath computes the relative path from generated file to flix json file. +// This path is used in the binding file to reference the flix json file. +func GetRelativePath(configFile, bindingFile string) (string, error) { + relPath, err := filepath.Rel(filepath.Dir(bindingFile), configFile) if err != nil { return "", err } From 82452a82d2a260b18b93e69cfcd57b971e59c04f Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 21 Nov 2023 16:58:26 -0700 Subject: [PATCH 16/18] updated to create only the directories passed in to save flag, had issues with it trying to create the file as a directory. Added aliases in flow json to dep contracts --- internal/command/result.go | 5 +++- internal/super/flix.go | 49 ++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/internal/command/result.go b/internal/command/result.go index b39758094..ed9be9266 100644 --- a/internal/command/result.go +++ b/internal/command/result.go @@ -23,6 +23,7 @@ import ( "errors" "fmt" "os" + "path/filepath" "strings" "github.com/onflow/flow-go-sdk/access/grpc" @@ -87,7 +88,9 @@ func outputResult(result string, saveFlag string, formatFlag string, filterFlag Fs: afero.NewOsFs(), } - err := af.MkdirAll(saveFlag, 0644) + // create directory if doesn't exist + dir := filepath.Dir(saveFlag) + err := af.MkdirAll(dir, 0644) if err != nil { return err } diff --git a/internal/super/flix.go b/internal/super/flix.go index a6ba01e50..fe659284b 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -355,18 +355,53 @@ func GetDeployedContracts(state *flowkit.State) []flixkit.Contracts { if err != nil { continue } - for _, contract := range contracts { + for _, c := range contracts { contract := flixkit.Contracts{ - contract.Name: flixkit.Networks{ - deployment.Network: flixkit.Network{ - Address: "0x" + contract.AccountAddress.String(), - FqAddress: "A." + contract.AccountAddress.String() + "." + contract.Name, - Contract: contract.Name, - }, + c.Name: flixkit.Networks{ + deployment.Network: createFlixNetworkContract( + networkContract{ + contractName: c.Name, + networkAddress: c.AccountAddress.String(), + }), }, } depContracts = append(depContracts, contract) } } + // Networks of interest + networks := []config.Network{ + config.MainnetNetwork, + config.TestnetNetwork, + } + + for _, net := range networks { + locAliases := state.AliasesForNetwork(net) + for name, addr := range locAliases { + contract := flixkit.Contracts{ + name: flixkit.Networks{ + net.Name: createFlixNetworkContract( + networkContract{ + contractName: name, + networkAddress: addr, + }), + }, + } + depContracts = append(depContracts, contract) + } + } + return depContracts } + +type networkContract struct { + contractName string + networkAddress string +} + +func createFlixNetworkContract(contract networkContract) flixkit.Network { + return flixkit.Network{ + Address: "0x" + contract.networkAddress, + FqAddress: "A." + contract.networkAddress + "." + contract.contractName, + Contract: contract.contractName, + } +} From 360ac650e371d50e54d51942e37ed996513397c0 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 21 Nov 2023 17:01:44 -0700 Subject: [PATCH 17/18] made sure relative path is in unix format --- internal/super/flix.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index fe659284b..3a091ef2b 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -345,7 +345,8 @@ func GetRelativePath(configFile, bindingFile string) (string, error) { relPath = "./" + relPath } - return relPath, nil + // Currently binding files are js, we need to convert the path to unix style + return filepath.ToSlash(relPath), nil } func GetDeployedContracts(state *flowkit.State) []flixkit.Contracts { From 666f705299306500148df9eae35c213a174c62f5 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 22 Nov 2023 09:23:55 -0700 Subject: [PATCH 18/18] fix doc syntax --- internal/super/flix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 3a091ef2b..5a5ef7416 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -92,7 +92,7 @@ var packageCommand = &command.Command{ var generateCommand = &command.Command{ Cmd: &cobra.Command{ - Use: "generate cadence.cdc", + Use: "generate ", Short: "generate FLIX json template given local Cadence filename", Example: "flow flix generate multiply.cdc", Args: cobra.MinimumNArgs(1),