Skip to content

Commit

Permalink
Support flix (#158)
Browse files Browse the repository at this point in the history
* preliminary flix support

* fixing error message

* set default context

* structure if correctly

* addeed to readme

* remove flix folder name

* remove uneeded is transaction code

* update deps
  • Loading branch information
bjartek committed Mar 14, 2024
1 parent ccbc7bc commit 6d03979
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 48 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ The following env vars are supported
- OVEFFLOW_CONTINUE: if you do not want overflow to deploy contracts and accounts on emulator you can set this to true
- OVERFLOW_LOGGING: Set this to 0-4 to get increasing log

## Usage flix
```package main
import (
. "github.com/bjartek/overflow/v2"
)
func main() {
o := Overflow(WithNetwork("mainnet"))
o.FlixTx("transfer-flow",
WithSigner("<yoursigner>"),
WithArg("amount", 0.42),
WithArg("to", "0x886f3aeaf848c535"),
).Print()
}```

This will send 0.42 flow to me on mainnet. You need a go file with that content and a valid flow.json that is it



## Migrating from v1 api

Expand Down
57 changes: 57 additions & 0 deletions flix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package overflow

// run a script with the given code/filanem an options
func (o *OverflowState) FlixScript(filename string, opts ...OverflowInteractionOption) *OverflowScriptResult {
interaction := o.BuildInteraction(filename, "flix", opts...)

result := interaction.runScript()

if interaction.PrintOptions != nil && !interaction.NoLog {
result.Print()
}
if o.StopOnError && result.Err != nil {
result.PrintArguments(nil)
panic(result.Err)
}
return result
}

// compose interactionOptions into a new Script function
func (o *OverflowState) FlixScriptFN(outerOpts ...OverflowInteractionOption) OverflowScriptFunction {
return func(filename string, opts ...OverflowInteractionOption) *OverflowScriptResult {
outerOpts = append(outerOpts, opts...)
return o.FlixScript(filename, outerOpts...)
}
}

// compose fileName and interactionOptions into a new Script function
func (o *OverflowState) FlixScriptFileNameFN(filename string, outerOpts ...OverflowInteractionOption) OverflowScriptOptsFunction {
return func(opts ...OverflowInteractionOption) *OverflowScriptResult {
outerOpts = append(outerOpts, opts...)
return o.FlixScript(filename, outerOpts...)
}
}

// If you store this in a struct and add arguments to it it will not reset between calls
func (o *OverflowState) FlixTxFN(outerOpts ...OverflowInteractionOption) OverflowTransactionFunction {
return func(filename string, opts ...OverflowInteractionOption) *OverflowResult {
// outer has to be first since we need to be able to overwrite
opts = append(outerOpts, opts...)
return o.FlixTx(filename, opts...)
}
}

func (o *OverflowState) FlixTxFileNameFN(filename string, outerOpts ...OverflowInteractionOption) OverflowTransactionOptsFunction {
return func(opts ...OverflowInteractionOption) *OverflowResult {
// outer has to be first since we need to be able to overwrite
opts = append(outerOpts, opts...)
return o.FlixTx(filename, opts...)
}
}

// run a flix transaction with the given code/filanem an options
func (o *OverflowState) FlixTx(filename string, opts ...OverflowInteractionOption) *OverflowResult {
interaction := o.BuildInteraction(filename, "flix", opts...)

return o.sendTx(interaction)
}
26 changes: 14 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/fatih/color v1.16.0
github.com/hexops/autogold v1.3.1
github.com/onflow/cadence v1.0.0-preview.13
github.com/onflow/flixkit-go v1.2.1-cadence-v1-preview.5
github.com/onflow/flow-emulator v1.0.0-preview.11
github.com/onflow/flow-go v0.34.0-crescendo-preview.6.0.20240313030147-6c1b120ed2ac
github.com/onflow/flow-go-sdk v1.0.0-preview.11
Expand Down Expand Up @@ -38,9 +39,9 @@ require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // 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/btcsuite/btcd/chaincfg/chainhash v1.0.3 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand All @@ -53,7 +54,7 @@ require (
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.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/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand Down Expand Up @@ -96,7 +97,7 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/hexops/valast v1.4.3 // indirect
github.com/hexops/valast v1.4.4 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
Expand Down Expand Up @@ -159,7 +160,7 @@ require (
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // 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.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
Expand All @@ -168,7 +169,7 @@ require (
github.com/psiemens/sconfig v0.1.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.10.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/slok/go-http-metrics v0.10.0 // indirect
Expand All @@ -178,6 +179,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/supranational/blst v0.3.11 // indirect
Expand All @@ -202,15 +204,15 @@ require (
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/api v0.151.0 // indirect
Expand All @@ -226,6 +228,6 @@ require (
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.28.0 // indirect
mvdan.cc/gofumpt v0.4.0 // indirect
mvdan.cc/gofumpt v0.5.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit 6d03979

Please sign in to comment.