diff --git a/cmd/root.go b/cmd/root.go index 482b038db..6b54ce00c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -77,15 +77,10 @@ func NewRootCommand() *cobra.Command { store.AddCommand(NewStorageScan()) store.AddCommand(NewStorageDelete()) - scriptExec := NewScriptExec() - scriptCheck := NewScriptCheck() - root.AddCommand(serve) root.AddCommand(conf) root.AddCommand(UICmd) root.AddCommand(store) - root.AddCommand(scriptExec) - root.AddCommand(scriptCheck) root.AddCommand(version) root.AddCommand(stickersCmd) diff --git a/cmd/script_check.go b/cmd/script_check.go deleted file mode 100644 index b4cb690bd..000000000 --- a/cmd/script_check.go +++ /dev/null @@ -1,30 +0,0 @@ -package cmd - -import ( - "fmt" - "os" - - "github.com/formancehq/ledger/pkg/machine/script/compiler" - "github.com/spf13/cobra" -) - -func NewScriptCheck() *cobra.Command { - return &cobra.Command{ - Use: "check [script]", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - b, err := os.ReadFile(args[0]) - if err != nil { - return err - } - - _, err = compiler.Compile(string(b)) - if err != nil { - return err - } else { - fmt.Println("Script is correct ✅") - } - return nil - }, - } -} diff --git a/cmd/script_exec.go b/cmd/script_exec.go deleted file mode 100644 index 9b7b3ba8d..000000000 --- a/cmd/script_exec.go +++ /dev/null @@ -1,108 +0,0 @@ -package cmd - -import ( - "bytes" - "encoding/json" - "fmt" - "net/http" - "net/url" - "os" - "regexp" - - "github.com/formancehq/ledger/pkg/api/controllers" - "github.com/gin-gonic/gin" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -const ( - previewFlag = "preview" -) - -func NewScriptExec() *cobra.Command { - cmd := &cobra.Command{ - Use: "exec [ledger] [script]", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - b, err := os.ReadFile(args[1]) - if err != nil { - return err - } - - r := regexp.MustCompile(`^\n`) - s := string(b) - s = r.ReplaceAllString(s, "") - - b, err = json.Marshal(gin.H{ - "plain": s, - }) - if err != nil { - return err - } - - logrus.Debugln(string(b)) - - req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("http://%s/%s/script", - viper.Get(bindFlag), - args[0]), bytes.NewReader(b)) - if err != nil { - return err - } - - values := url.Values{} - if viper.GetBool(previewFlag) { - values.Set("preview", "yes") - } - req.URL.RawQuery = values.Encode() - req.Header.Set("Content-Type", "application/json") - - res, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - - result := controllers.ScriptResponse{} - err = json.NewDecoder(res.Body).Decode(&result) - if err != nil { - return err - } - - if result.ErrorCode != "" { - switch result.ErrorCode { - case "INTERNAL": - return errors.New("unexpected error occurred") - default: - return fmt.Errorf("unexpected error: %s", result.ErrorMessage) - } - } - - fmt.Println("Script ran successfully ✅") - fmt.Println("Tx resume:") - fmt.Printf("ID: %d\r\n", result.Transaction.ID) - fmt.Println("Postings:") - for _, p := range result.Transaction.Postings { - fmt.Printf( - "\t Source: %s, Destination: %s, Amount: %s, Asset: %s\r\n", - p.Source, - p.Destination, - p.Amount, - p.Asset, - ) - } - if !viper.GetBool(previewFlag) { - fmt.Printf("Created transaction: http://%s/%s/transactions/%d\r\n", - viper.Get(bindFlag), - args[0], - result.Transaction.ID) - } - return nil - }, - } - cmd.Flags().Bool(previewFlag, false, "Preview mode (does not save transactions)") - if err := viper.BindPFlags(cmd.Flags()); err != nil { - panic(err) - } - return cmd -} diff --git a/cmd/script_test.go b/cmd/script_test.go deleted file mode 100644 index 63fd92812..000000000 --- a/cmd/script_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package cmd - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "testing" - "time" - - "github.com/formancehq/ledger/pkg/api/controllers" - "github.com/formancehq/ledger/pkg/core" - "github.com/formancehq/stack/libs/go-libs/api" - "github.com/formancehq/stack/libs/go-libs/pgtesting" - "github.com/google/go-cmp/cmp" - "github.com/google/uuid" - "github.com/spf13/viper" - "github.com/stretchr/testify/require" -) - -func Test_ScriptCommands(t *testing.T) { - - db := pgtesting.NewPostgresDatabase(t) - - ledger := uuid.NewString() - viper.Set("name", ledger) - viper.Set(storageDriverFlag, "postgres") - viper.Set(storagePostgresConnectionStringFlag, db.ConnString()) - require.NoError(t, NewStorageInit().Execute()) - - d1 := []byte(` - send [EUR 1] ( - source = @world - destination = @alice - )`) - path := filepath.Join(os.TempDir(), "script") - require.NoError(t, os.WriteFile(path, d1, 0644)) - - httpServer := httptest.NewServer(http.HandlerFunc(scriptSuccessHandler)) - defer func() { - httpServer.CloseClientConnections() - httpServer.Close() - }() - - tests := map[string]struct { - args []string - flags map[string]any - want error - }{ - "not enough args": {args: []string{path}, flags: map[string]any{}, want: errors.New("accepts 2 arg(s), received 1")}, - "success": {args: []string{ledger, path}, flags: map[string]any{bindFlag: httpServer.URL[7:]}, want: nil}, - "preview": {args: []string{ledger, path}, flags: map[string]any{previewFlag: true}, want: nil}, - } - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - for i, f := range tc.flags { - viper.Set(i, f) - } - cmd := NewScriptExec() - cmd.SetArgs(tc.args) - got := cmd.Execute() - if tc.want != nil { - if got == nil { - t.Fatalf("an error is expected, but got nil") - } - diff := cmp.Diff(tc.want.Error(), got.Error()) - if diff != "" { - t.Fatalf(diff) - } - } - }) - } -} - -func scriptSuccessHandler(w http.ResponseWriter, _ *http.Request) { - resp := controllers.ScriptResponse{ - ErrorResponse: api.ErrorResponse{}, - Transaction: &core.ExpandedTransaction{ - Transaction: core.Transaction{ - TransactionData: core.TransactionData{ - Postings: core.Postings{ - { - Source: "world", - Destination: "alice", - Amount: core.NewMonetaryInt(1), - Asset: "EUR", - }, - }, - Timestamp: time.Now(), - }, - }, - PreCommitVolumes: nil, - PostCommitVolumes: nil, - }, - } - if err := json.NewEncoder(w).Encode(resp); err != nil { - fmt.Printf("ERR:%s\n", err) - } -} diff --git a/go.mod b/go.mod index 00b2ff75f..9c6b75486 100755 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/buger/jsonparser v1.1.1 github.com/dgraph-io/ristretto v0.1.1 github.com/formancehq/stack/libs/go-libs v0.0.0-20230222164357-55840b21a337 - github.com/gin-gonic/gin v1.9.0 github.com/go-chi/chi/v5 v5.0.8 github.com/go-chi/cors v1.2.1 github.com/go-redis/redis/v8 v8.11.5 @@ -50,10 +49,8 @@ require ( github.com/ThreeDotsLabs/watermill-kafka/v2 v2.2.2 // indirect github.com/ThreeDotsLabs/watermill-nats/v2 v2.0.0 // indirect github.com/ajg/form v1.5.1 // indirect - github.com/bytedance/sonic v1.8.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/containerd/continuity v0.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect @@ -67,15 +64,10 @@ require ( github.com/eapache/queue v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-chi/chi v4.1.2+incompatible // indirect github.com/go-chi/render v1.0.2 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.11.2 // indirect - github.com/goccy/go-json v0.10.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.0.0 // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -96,16 +88,10 @@ require ( github.com/jcmturner/gofork v1.7.6 // indirect github.com/jcmturner/gokrb5/v8 v8.4.3 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect - github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.15.15 // indirect - github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/leodido/go-urn v1.2.1 // indirect github.com/lithammer/shortuuid/v3 v3.0.7 // indirect github.com/magiconair/properties v1.8.7 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect github.com/nats-io/nats.go v1.23.0 // indirect github.com/nats-io/nkeys v0.3.0 // indirect github.com/nats-io/nuid v1.0.1 // indirect @@ -124,8 +110,6 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect - github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.10 // indirect github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.21 // indirect github.com/uptrace/opentelemetry-go-extra/otelutil v0.1.21 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect @@ -151,7 +135,6 @@ require ( go.uber.org/dig v1.16.1 // indirect go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/arch v0.2.0 // indirect golang.org/x/crypto v0.6.0 // indirect golang.org/x/mod v0.8.0 // indirect golang.org/x/net v0.8.0 // indirect diff --git a/go.sum b/go.sum index e76343efa..b73bcd808 100644 --- a/go.sum +++ b/go.sum @@ -76,9 +76,6 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.8.1 h1:NqAHCaGaTzro0xMmnTCLUyRlbEP6r8MCA1cJUrH3Pu4= -github.com/bytedance/sonic v1.8.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= @@ -88,9 +85,6 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -158,10 +152,6 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4 github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= -github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= @@ -185,13 +175,6 @@ github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= -github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= -github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= -github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= -github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= -github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= github.com/go-redis/redis/v8 v8.8.0/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= @@ -199,8 +182,6 @@ github.com/go-redis/redismock/v8 v8.0.6 h1:rtuijPgGynsRB2Y7KDACm09WvjHWS4RaG44Nm github.com/go-redis/redismock/v8 v8.0.6/go.mod h1:sDIF73OVsmaKzYe/1FJXGiCQ4+oHYbzjpaL9Vor0sS4= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= -github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -256,7 +237,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ 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/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -336,8 +316,6 @@ github.com/jcmturner/gokrb5/v8 v8.4.3/go.mod h1:dqRwJGXznQrzw6cWmyo6kH+E7jksEQG/ github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -346,9 +324,6 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -358,8 +333,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lithammer/shortuuid/v3 v3.0.4/go.mod h1:RviRjexKqIzx/7r1peoAITm6m7gnif/h+0zmolKJjzw= @@ -369,8 +342,6 @@ github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczG github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -380,12 +351,8 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU= github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI= github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI= @@ -485,7 +452,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -496,10 +462,6 @@ github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8 github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/swaggest/assertjson v1.7.0 h1:SKw5Rn0LQs6UvmGrIdaKQbMR1R3ncXm5KNon+QJ7jtw= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= -github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= -github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go/codec v1.2.10 h1:eimT6Lsr+2lzmSZxPhLFoOWFmQqwk0fllJJ5hEbTXtQ= -github.com/ugorji/go/codec v1.2.10/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.21 h1:OXsouNDvuET5o1A4uvoCnAXuuNke8JlfZWceciyUlC8= github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.21/go.mod h1:Xm3wlRGm5xzdAGPOvqydXPiGj0Da1q0OlUNm7Utoda4= github.com/uptrace/opentelemetry-go-extra/otelutil v0.1.21 h1:HCqo51kNF8wxDMDhxcN5S6DlfZXigMtptRpkvjBCeVc= @@ -588,9 +550,6 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.2.0 h1:W1sUEHXiJTfjaFJ5SLo0N6lZn+0eO5gWD1MFeTGqQEY= -golang.org/x/arch v0.2.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -756,10 +715,8 @@ golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= @@ -977,6 +934,5 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/pkg/api/controllers/controllers.go b/pkg/api/controllers/controllers.go index 90da2aa4d..f5404771d 100644 --- a/pkg/api/controllers/controllers.go +++ b/pkg/api/controllers/controllers.go @@ -19,7 +19,6 @@ var Module = fx.Options( fx.Annotate(NewConfigController, fx.ParamTags(versionKey)), ), fx.Provide(NewLedgerController), - fx.Provide(NewScriptController), fx.Provide(NewAccountController), fx.Provide(NewTransactionController), fx.Provide(NewBalanceController), diff --git a/pkg/api/controllers/script_controller.go b/pkg/api/controllers/script_controller.go deleted file mode 100644 index f98be9606..000000000 --- a/pkg/api/controllers/script_controller.go +++ /dev/null @@ -1,66 +0,0 @@ -package controllers - -import ( - "encoding/json" - "net/http" - "strings" - - "github.com/formancehq/ledger/pkg/api/apierrors" - "github.com/formancehq/ledger/pkg/core" - "github.com/formancehq/ledger/pkg/ledger" - sharedapi "github.com/formancehq/stack/libs/go-libs/api" - "github.com/formancehq/stack/libs/go-libs/logging" -) - -type ScriptResponse struct { - sharedapi.ErrorResponse - Transaction *core.ExpandedTransaction `json:"transaction,omitempty"` -} - -type ScriptController struct{} - -func NewScriptController() ScriptController { - return ScriptController{} -} - -func (ctl *ScriptController) PostScript(w http.ResponseWriter, r *http.Request) { - l := LedgerFromContext(r.Context()) - - var script core.ScriptData - if err := json.NewDecoder(r.Body).Decode(&script); err != nil { - panic(err) - } - - value := r.URL.Query().Get("preview") - preview := strings.ToUpper(value) == "YES" || strings.ToUpper(value) == "TRUE" || value == "1" - - res := ScriptResponse{} - execRes, err := l.ExecuteScript(r.Context(), preview, script) - if err != nil { - var ( - code = apierrors.ErrInternal - message string - ) - switch e := err.(type) { - case *ledger.ScriptError: - code = e.Code - message = e.Message - case *ledger.ConflictError: - code = apierrors.ErrConflict - message = e.Error() - default: - logging.FromContext(r.Context()).Errorf( - "internal errors executing script: %s", err) - } - res.ErrorResponse = sharedapi.ErrorResponse{ - ErrorCode: code, - ErrorMessage: message, - } - if message != "" { - res.Details = apierrors.EncodeLink(message) - } - } - res.Transaction = &execRes - - sharedapi.RawOk(w, res) -} diff --git a/pkg/api/controllers/script_controller_test.go b/pkg/api/controllers/script_controller_test.go deleted file mode 100644 index 09f44b6fa..000000000 --- a/pkg/api/controllers/script_controller_test.go +++ /dev/null @@ -1,281 +0,0 @@ -package controllers_test - -import ( - "context" - "encoding/json" - "net/http" - "net/url" - "testing" - - "github.com/formancehq/ledger/pkg/api" - "github.com/formancehq/ledger/pkg/api/apierrors" - "github.com/formancehq/ledger/pkg/api/controllers" - "github.com/formancehq/ledger/pkg/api/internal" - "github.com/formancehq/ledger/pkg/core" - "github.com/formancehq/ledger/pkg/ledger" - "github.com/formancehq/ledger/pkg/storage" - sharedapi "github.com/formancehq/stack/libs/go-libs/api" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.uber.org/fx" -) - -func TestPostScript(t *testing.T) { - type testCase struct { - name string - script core.ScriptData - expectedResponse controllers.ScriptResponse - } - - testCases := []testCase{ - { - name: "nominal", - script: core.ScriptData{ - Script: core.Script{ - Plain: ` - send [COIN 100] ( - source = @world - destination = @centralbank - ) - send [COIN 100] ( - source = @centralbank - destination = @users:001 - )`, - }, - }, - }, - { - name: "failure with insufficient funds", - script: core.ScriptData{ - Script: core.Script{ - Plain: ` - send [COIN 100] ( - source = @centralbank - destination = @users:001 - )`, - }, - }, - expectedResponse: controllers.ScriptResponse{ - ErrorResponse: sharedapi.ErrorResponse{ - ErrorCode: apierrors.ErrInsufficientFund, - ErrorMessage: "account had insufficient funds", - Details: apierrors.EncodeLink("account had insufficient funds"), - }, - }, - }, - { - name: "failure with metadata override", - script: core.ScriptData{ - Script: core.Script{ - Plain: ` - set_tx_meta("priority", "low") - - send [USD/2 99] ( - source=@world - destination=@user:001 - )`, - }, - Metadata: core.Metadata{ - "priority": json.RawMessage(`"high"`), - }, - }, - expectedResponse: controllers.ScriptResponse{ - ErrorResponse: sharedapi.ErrorResponse{ - ErrorCode: ledger.ScriptErrorMetadataOverride, - ErrorMessage: "cannot override metadata from script", - Details: apierrors.EncodeLink("cannot override metadata from script"), - }, - }, - }, - } - - internal.RunTest(t, fx.Invoke(func(lc fx.Lifecycle, api *api.API) { - lc.Append(fx.Hook{ - OnStart: func(ctx context.Context) error { - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - rsp := internal.PostScript(t, api, tc.script, url.Values{}) - require.Equal(t, http.StatusOK, rsp.Result().StatusCode) - - res := controllers.ScriptResponse{} - require.NoError(t, json.Unmarshal(rsp.Body.Bytes(), &res)) - - res.Transaction = nil - require.EqualValues(t, tc.expectedResponse, res) - }) - } - - return nil - }, - }) - })) -} - -func TestPostScriptPreview(t *testing.T) { - script := ` - send [COIN 100] ( - source = @world - destination = @centralbank - )` - - internal.RunTest(t, fx.Invoke(func(lc fx.Lifecycle, api *api.API, driver storage.Driver[ledger.Store]) { - lc.Append(fx.Hook{ - OnStart: func(ctx context.Context) error { - store := internal.GetLedgerStore(t, driver, ctx) - - t.Run("true", func(t *testing.T) { - values := url.Values{} - values.Set("preview", "true") - - rsp := internal.PostScript(t, api, core.ScriptData{ - Script: core.Script{Plain: script}, - }, values) - - require.Equal(t, http.StatusOK, rsp.Result().StatusCode) - res := controllers.ScriptResponse{} - internal.Decode(t, rsp.Body, &res) - - cursor, err := store.GetTransactions(ctx, *ledger.NewTransactionsQuery()) - require.NoError(t, err) - require.Len(t, cursor.Data, 0) - }) - - t.Run("false", func(t *testing.T) { - values := url.Values{} - values.Set("preview", "false") - - rsp := internal.PostScript(t, api, core.ScriptData{ - Script: core.Script{Plain: script}, - }, values) - - require.Equal(t, http.StatusOK, rsp.Result().StatusCode) - res := controllers.ScriptResponse{} - internal.Decode(t, rsp.Body, &res) - - cursor, err := store.GetTransactions(ctx, *ledger.NewTransactionsQuery()) - require.NoError(t, err) - require.Len(t, cursor.Data, 1) - }) - - return nil - }, - }) - })) -} - -func TestPostScriptWithReference(t *testing.T) { - internal.RunTest(t, fx.Invoke(func(lc fx.Lifecycle, api *api.API, driver storage.Driver[ledger.Store]) { - lc.Append(fx.Hook{ - OnStart: func(ctx context.Context) error { - reference := "order_1234" - rsp := internal.PostScript(t, api, core.ScriptData{ - Script: core.Script{ - Plain: ` - send [COIN 100] ( - source = @world - destination = @centralbank - )`}, - Reference: reference, - }, url.Values{}) - require.Equal(t, http.StatusOK, rsp.Result().StatusCode) - - res := controllers.ScriptResponse{} - require.NoError(t, json.Unmarshal(rsp.Body.Bytes(), &res)) - require.Equal(t, reference, res.Transaction.Reference) - - store := internal.GetLedgerStore(t, driver, ctx) - cursor, err := store.GetTransactions(ctx, *ledger.NewTransactionsQuery()) - require.NoError(t, err) - require.Len(t, cursor.Data, 1) - require.Equal(t, reference, cursor.Data[0].Reference) - - return nil - }, - }) - })) -} - -func TestPostScriptConflict(t *testing.T) { - script := ` - send [COIN 100] ( - source = @world - destination = @centralbank - )` - - internal.RunTest(t, fx.Invoke(func(lc fx.Lifecycle, api *api.API, driver storage.Driver[ledger.Store]) { - lc.Append(fx.Hook{ - OnStart: func(ctx context.Context) error { - t.Run("first should succeed", func(t *testing.T) { - rsp := internal.PostScript(t, api, core.ScriptData{ - Script: core.Script{ - Plain: script, - }, - Reference: "1234", - }, url.Values{}) - - assert.Equal(t, http.StatusOK, rsp.Result().StatusCode) - res := controllers.ScriptResponse{} - internal.Decode(t, rsp.Body, &res) - assert.Equal(t, "", res.ErrorCode) - assert.Equal(t, "", res.ErrorMessage) - assert.NotNil(t, res.Transaction) - }) - - t.Run("second should fail", func(t *testing.T) { - rsp := internal.PostScript(t, api, core.ScriptData{ - Script: core.Script{ - Plain: script, - }, - Reference: "1234", - }, url.Values{}) - - assert.Equal(t, http.StatusOK, rsp.Result().StatusCode) - res := controllers.ScriptResponse{} - internal.Decode(t, rsp.Body, &res) - assert.Equal(t, apierrors.ErrConflict, res.ErrorCode) - assert.Equal(t, "conflict error on reference", res.ErrorMessage) - }) - - return nil - }, - }) - })) -} - -func TestPostScriptWithSetAccountMeta(t *testing.T) { - internal.RunTest(t, fx.Invoke(func(lc fx.Lifecycle, api *api.API, driver storage.Driver[ledger.Store]) { - lc.Append(fx.Hook{ - OnStart: func(ctx context.Context) error { - rsp := internal.PostScript(t, api, core.ScriptData{ - Script: core.Script{ - Plain: ` - send [COIN 100] ( - source = @world - destination = @centralbank - ) - set_account_meta(@centralbank, "fees", "15 percent")`}, - }, url.Values{}) - require.Equal(t, http.StatusOK, rsp.Result().StatusCode) - - res := controllers.ScriptResponse{} - require.NoError(t, json.Unmarshal(rsp.Body.Bytes(), &res)) - require.Equal(t, core.Metadata{}, res.Transaction.Metadata) - - store := internal.GetLedgerStore(t, driver, ctx) - cursor, err := store.GetTransactions(ctx, *ledger.NewTransactionsQuery()) - require.NoError(t, err) - require.Len(t, cursor.Data, 1) - - acc, err := store.GetAccount(ctx, "centralbank") - require.NoError(t, err) - require.Equal(t, core.Metadata{ - "fees": map[string]any{ - "type": "string", - "value": "15 percent", - }}, acc.Metadata) - - return nil - }, - }) - })) -} diff --git a/pkg/api/routes/routes.go b/pkg/api/routes/routes.go index b8d38f94a..7ace25787 100644 --- a/pkg/api/routes/routes.go +++ b/pkg/api/routes/routes.go @@ -43,7 +43,6 @@ type Routes struct { healthController *health.HealthController configController controllers.ConfigController ledgerController controllers.LedgerController - scriptController controllers.ScriptController accountController controllers.AccountController balanceController controllers.BalanceController transactionController controllers.TransactionController @@ -61,7 +60,6 @@ func NewRoutes( ledgerMiddleware middlewares.LedgerMiddleware, configController controllers.ConfigController, ledgerController controllers.LedgerController, - scriptController controllers.ScriptController, accountController controllers.AccountController, balanceController controllers.BalanceController, transactionController controllers.TransactionController, @@ -77,7 +75,6 @@ func NewRoutes( ledgerMiddleware: ledgerMiddleware, configController: configController, ledgerController: ledgerController, - scriptController: scriptController, accountController: accountController, balanceController: balanceController, transactionController: transactionController, @@ -155,12 +152,6 @@ func (r *Routes) Engine() *chi.Mux { // MappingController router.Get("/mapping", r.mappingController.GetMapping) router.Put("/mapping", r.mappingController.PutMapping) - - // ScriptController - router.With( - middlewares.Transaction(r.locker), - idempotency.Middleware(r.idempotencyStore), - ).Post("/script", r.scriptController.PostScript) }) })