From 77feb9ea48d6fdbb867e0e9c9de32f649e86c03a Mon Sep 17 00:00:00 2001 From: Pouya Date: Tue, 20 Feb 2024 00:25:29 +0100 Subject: [PATCH 1/2] Add multi-asset price tracking --- go.work.sum | 76 ++++ src/cmd/broker.go | 2 + src/cmd/worker.go | 1 + src/config/config.go | 2 +- src/constants/constants.go | 4 +- src/datasets/uniswap.go | 3 + src/ent/assetprice.go | 55 ++- src/ent/assetprice/assetprice.go | 47 +-- src/ent/assetprice/where.go | 255 +++++++++++- src/ent/assetprice_create.go | 255 ++++++++++-- src/ent/assetprice_query.go | 107 +---- src/ent/assetprice_update.go | 283 ++++++------- src/ent/client.go | 179 +------- src/ent/dataset.go | 129 ------ src/ent/dataset/dataset.go | 87 ---- src/ent/dataset/where.go | 162 -------- src/ent/dataset_create.go | 491 ---------------------- src/ent/dataset_delete.go | 88 ---- src/ent/dataset_query.go | 636 ---------------------------- src/ent/dataset_update.go | 398 ------------------ src/ent/ent.go | 2 - src/ent/hook/hook.go | 12 - src/ent/migrate/schema.go | 56 +-- src/ent/mutation.go | 691 +++++++++---------------------- src/ent/predicate/predicate.go | 3 - src/ent/runtime.go | 7 - src/ent/schema/assetprice.go | 10 +- src/ent/schema/dataset.go | 35 -- src/ent/tx.go | 3 - src/net/server.go | 3 +- src/plugins/uniswap/uniswap.go | 305 +++++++++----- 31 files changed, 1173 insertions(+), 3214 deletions(-) delete mode 100644 src/ent/dataset.go delete mode 100644 src/ent/dataset/dataset.go delete mode 100644 src/ent/dataset/where.go delete mode 100644 src/ent/dataset_create.go delete mode 100644 src/ent/dataset_delete.go delete mode 100644 src/ent/dataset_query.go delete mode 100644 src/ent/dataset_update.go delete mode 100644 src/ent/schema/dataset.go diff --git a/go.work.sum b/go.work.sum index 81be5d79..d276d52b 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,53 +1,129 @@ +cloud.google.com/go v0.110.10/go.mod h1:v1OoFqYxiBkUrruItNM3eT4lLByNjxmJSV/xDKJNnic= +cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go/firestore v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ= +cloud.google.com/go/iam v1.1.5/go.mod h1:rB6P/Ic3mykPbFio+vo7403drjlgvoWfYpJhMXEbzv8= +cloud.google.com/go/longrunning v0.5.4/go.mod h1:zqNVncI0BOP8ST6XQD1+VcvuShMmq7+xFSzOL++V0dI= +cloud.google.com/go/storage v1.35.1/go.mod h1:M6M/3V/D3KpzMTJyPOR/HU6n2Si5QdaXYEsng2xgOs8= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0/go.mod h1:+6KLcKIVgxoBDMqMO/Nvy7bZ9a0nbU3I1DtFQK3YvB4= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= +github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4= +github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM= +github.com/aws/aws-sdk-go-v2/config v1.18.45/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37/go.mod h1:Qe+2KtKml+FEsQF/DHmDV+xjtche/hwoF75EG4UlHW8= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/route53 v1.30.2/go.mod h1:TQZBt/WaQy+zTHoW++rnl8JBrmZ0VO6EUbVua1+foCA= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= +github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= +github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= +github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs= +github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= +github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= +github.com/cloudflare/cloudflare-go v0.79.0/go.mod h1:gkHQf9xEubaQPEuerBuoinR9P8bf8a05Lq0X6WKy1Oc= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M= github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= +github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg= +github.com/ferranbt/fastssz v0.1.2/go.mod h1:X5UPrE2u1UJjxHA8X54u04SBwdAQjG2sFtWs39YxyWs= +github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= +github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61/go.mod h1:Q0X6pkwTILDlzrGEckF6HKjXe48EgsY/l7K7vhY4MW8= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= +github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg= +github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= +github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU= +github.com/googleapis/google-cloud-go-testing v0.0.0-20210719221736-1c9a4c676720/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= +github.com/hashicorp/consul/api v1.25.1/go.mod h1:iiLVwR/htV7mas/sy0O+XSuEnrdBUUydemjxcUrAt4g= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4= +github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8= github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= +github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= +github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267/go.mod h1:h1nSAbGFqGVzn6Jyl1R/iCcBUHN4g+gW1u9CoBTrb9E= +github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 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/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= +github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= +github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8= +github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADymtkpts= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/sftp v1.13.6/go.mod h1:tz1ryNURKu77RL+GuCzmoJYxQczL3wLNNpPWagdg4Qk= +github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7/go.mod h1:IToEjHuttnUzwZI5KBSM/LOOW3qLbbrHOEfp3SbECGY= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/sagikazarmark/crypt v0.17.0/go.mod h1:SMtHTvdmsZMuY/bpZoqokSoChIrcJ/epOxZN58PbZDg= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +go.etcd.io/etcd/api/v3 v3.5.10/go.mod h1:TidfmT4Uycad3NM/o25fG3J07odo4GBB9hoxaodFCtI= +go.etcd.io/etcd/client/pkg/v3 v3.5.10/go.mod h1:DYivfIviIuQ8+/lCq4vcxuseg2P2XbHygkKwFo9fc8U= +go.etcd.io/etcd/client/v2 v2.305.10/go.mod h1:m3CKZi69HzilhVqtPDcjhSGp+kA1OmbNn0qamH80xjA= +go.etcd.io/etcd/client/v3 v3.5.10/go.mod h1:RVeBnDz2PUEZqTpgqwAtUd8nAPf5kjyFyND7P1VkOKc= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +google.golang.org/api v0.153.0/go.mod h1:3qNJX5eOmhiWYc67jRA/3GsDw97UFb5ivv7Y2PrriAY= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= +google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc= google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= diff --git a/src/cmd/broker.go b/src/cmd/broker.go index 71f22a6f..1b84fba1 100644 --- a/src/cmd/broker.go +++ b/src/cmd/broker.go @@ -8,6 +8,7 @@ import ( "github.com/KenshiTech/unchained/db" "github.com/KenshiTech/unchained/ethereum" "github.com/KenshiTech/unchained/net" + "github.com/KenshiTech/unchained/plugins/uniswap" "github.com/spf13/cobra" ) @@ -21,6 +22,7 @@ var brokerCmd = &cobra.Command{ config.LoadConfig(configPath, secretsPath) db.Start() ethereum.Start() + uniswap.Setup() net.StartServer() }, } diff --git a/src/cmd/worker.go b/src/cmd/worker.go index 76918a7f..524ec86a 100644 --- a/src/cmd/worker.go +++ b/src/cmd/worker.go @@ -31,6 +31,7 @@ var workerCmd = &cobra.Command{ bls.InitClientIdentity() client.StartClient() ethereum.Start() + uniswap.Setup() uniswap.Start() client.ClientBlock() }, diff --git a/src/config/config.go b/src/config/config.go index 0eba3f1c..bee6a60c 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -10,7 +10,7 @@ import ( func defaults() { Config.SetDefault("name", petname.Generate(3, "-")) Config.SetDefault("log", "info") - Config.SetDefault("rpc.ethereum", "https://eth.llamarpc.com") + Config.SetDefault("plugins.uniswap.rpc.ethereum", "https://ethereum.publicnode.com") Config.SetDefault("broker", "wss://shinobi.brokers.kenshi.io") } diff --git a/src/constants/constants.go b/src/constants/constants.go index 2ff84ab7..18410ff9 100644 --- a/src/constants/constants.go +++ b/src/constants/constants.go @@ -1,4 +1,4 @@ package constants -var Version = "0.11.6" -var ProtocolVersion = "0.11.5" +var Version = "0.11.7" +var ProtocolVersion = "0.11.7" diff --git a/src/datasets/uniswap.go b/src/datasets/uniswap.go index c8733b15..9652eafe 100644 --- a/src/datasets/uniswap.go +++ b/src/datasets/uniswap.go @@ -5,6 +5,9 @@ import "math/big" type PriceInfo struct { Block uint64 Price big.Int + Asset string + Chain string + Pair string } type PriceReport struct { diff --git a/src/ent/assetprice.go b/src/ent/assetprice.go index d8648260..98b73f2c 100644 --- a/src/ent/assetprice.go +++ b/src/ent/assetprice.go @@ -25,6 +25,12 @@ type AssetPrice struct { Price *big.Int `json:"price,omitempty"` // Signature holds the value of the "signature" field. Signature []byte `json:"signature,omitempty"` + // Asset holds the value of the "asset" field. + Asset string `json:"asset,omitempty"` + // Chain holds the value of the "chain" field. + Chain string `json:"chain,omitempty"` + // Pair holds the value of the "pair" field. + Pair string `json:"pair,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the AssetPriceQuery when eager-loading is set. Edges AssetPriceEdges `json:"edges"` @@ -33,28 +39,17 @@ type AssetPrice struct { // AssetPriceEdges holds the relations/edges for other nodes in the graph. type AssetPriceEdges struct { - // DataSet holds the value of the dataSet edge. - DataSet []*DataSet `json:"dataSet,omitempty"` // Signers holds the value of the signers edge. Signers []*Signer `json:"signers,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [2]bool -} - -// DataSetOrErr returns the DataSet value or an error if the edge -// was not loaded in eager-loading. -func (e AssetPriceEdges) DataSetOrErr() ([]*DataSet, error) { - if e.loadedTypes[0] { - return e.DataSet, nil - } - return nil, &NotLoadedError{edge: "dataSet"} + loadedTypes [1]bool } // SignersOrErr returns the Signers value or an error if the edge // was not loaded in eager-loading. func (e AssetPriceEdges) SignersOrErr() ([]*Signer, error) { - if e.loadedTypes[1] { + if e.loadedTypes[0] { return e.Signers, nil } return nil, &NotLoadedError{edge: "signers"} @@ -69,6 +64,8 @@ func (*AssetPrice) scanValues(columns []string) ([]any, error) { values[i] = new([]byte) case assetprice.FieldID, assetprice.FieldBlock, assetprice.FieldSignersCount: values[i] = new(sql.NullInt64) + case assetprice.FieldAsset, assetprice.FieldChain, assetprice.FieldPair: + values[i] = new(sql.NullString) case assetprice.FieldPrice: values[i] = assetprice.ValueScanner.Price.ScanValue() default: @@ -117,6 +114,24 @@ func (ap *AssetPrice) assignValues(columns []string, values []any) error { } else if value != nil { ap.Signature = *value } + case assetprice.FieldAsset: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field asset", values[i]) + } else if value.Valid { + ap.Asset = value.String + } + case assetprice.FieldChain: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field chain", values[i]) + } else if value.Valid { + ap.Chain = value.String + } + case assetprice.FieldPair: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field pair", values[i]) + } else if value.Valid { + ap.Pair = value.String + } default: ap.selectValues.Set(columns[i], values[i]) } @@ -130,11 +145,6 @@ func (ap *AssetPrice) Value(name string) (ent.Value, error) { return ap.selectValues.Get(name) } -// QueryDataSet queries the "dataSet" edge of the AssetPrice entity. -func (ap *AssetPrice) QueryDataSet() *DataSetQuery { - return NewAssetPriceClient(ap.config).QueryDataSet(ap) -} - // QuerySigners queries the "signers" edge of the AssetPrice entity. func (ap *AssetPrice) QuerySigners() *SignerQuery { return NewAssetPriceClient(ap.config).QuerySigners(ap) @@ -176,6 +186,15 @@ func (ap *AssetPrice) String() string { builder.WriteString(", ") builder.WriteString("signature=") builder.WriteString(fmt.Sprintf("%v", ap.Signature)) + builder.WriteString(", ") + builder.WriteString("asset=") + builder.WriteString(ap.Asset) + builder.WriteString(", ") + builder.WriteString("chain=") + builder.WriteString(ap.Chain) + builder.WriteString(", ") + builder.WriteString("pair=") + builder.WriteString(ap.Pair) builder.WriteByte(')') return builder.String() } diff --git a/src/ent/assetprice/assetprice.go b/src/ent/assetprice/assetprice.go index 7041da51..c1958c33 100644 --- a/src/ent/assetprice/assetprice.go +++ b/src/ent/assetprice/assetprice.go @@ -23,17 +23,16 @@ const ( FieldPrice = "price" // FieldSignature holds the string denoting the signature field in the database. FieldSignature = "signature" - // EdgeDataSet holds the string denoting the dataset edge name in mutations. - EdgeDataSet = "dataSet" + // FieldAsset holds the string denoting the asset field in the database. + FieldAsset = "asset" + // FieldChain holds the string denoting the chain field in the database. + FieldChain = "chain" + // FieldPair holds the string denoting the pair field in the database. + FieldPair = "pair" // EdgeSigners holds the string denoting the signers edge name in mutations. EdgeSigners = "signers" // Table holds the table name of the assetprice in the database. Table = "asset_prices" - // DataSetTable is the table that holds the dataSet relation/edge. The primary key declared below. - DataSetTable = "asset_price_dataSet" - // DataSetInverseTable is the table name for the DataSet entity. - // It exists in this package in order to avoid circular dependency with the "dataset" package. - DataSetInverseTable = "data_sets" // SignersTable is the table that holds the signers relation/edge. The primary key declared below. SignersTable = "asset_price_signers" // SignersInverseTable is the table name for the Signer entity. @@ -48,12 +47,12 @@ var Columns = []string{ FieldSignersCount, FieldPrice, FieldSignature, + FieldAsset, + FieldChain, + FieldPair, } var ( - // DataSetPrimaryKey and DataSetColumn2 are the table columns denoting the - // primary key for the dataSet relation (M2M). - DataSetPrimaryKey = []string{"asset_price_id", "data_set_id"} // SignersPrimaryKey and SignersColumn2 are the table columns denoting the // primary key for the signers relation (M2M). SignersPrimaryKey = []string{"asset_price_id", "signer_id"} @@ -101,18 +100,19 @@ func ByPrice(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldPrice, opts...).ToFunc() } -// ByDataSetCount orders the results by dataSet count. -func ByDataSetCount(opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newDataSetStep(), opts...) - } +// ByAsset orders the results by the asset field. +func ByAsset(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAsset, opts...).ToFunc() } -// ByDataSet orders the results by dataSet terms. -func ByDataSet(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newDataSetStep(), append([]sql.OrderTerm{term}, terms...)...) - } +// ByChain orders the results by the chain field. +func ByChain(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldChain, opts...).ToFunc() +} + +// ByPair orders the results by the pair field. +func ByPair(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPair, opts...).ToFunc() } // BySignersCount orders the results by signers count. @@ -128,13 +128,6 @@ func BySigners(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { sqlgraph.OrderByNeighborTerms(s, newSignersStep(), append([]sql.OrderTerm{term}, terms...)...) } } -func newDataSetStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(DataSetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, DataSetTable, DataSetPrimaryKey...), - ) -} func newSignersStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/src/ent/assetprice/where.go b/src/ent/assetprice/where.go index 7ee7b5b8..659a24c4 100644 --- a/src/ent/assetprice/where.go +++ b/src/ent/assetprice/where.go @@ -77,6 +77,21 @@ func Signature(v []byte) predicate.AssetPrice { return predicate.AssetPrice(sql.FieldEQ(FieldSignature, v)) } +// Asset applies equality check predicate on the "asset" field. It's identical to AssetEQ. +func Asset(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEQ(FieldAsset, v)) +} + +// Chain applies equality check predicate on the "chain" field. It's identical to ChainEQ. +func Chain(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEQ(FieldChain, v)) +} + +// Pair applies equality check predicate on the "pair" field. It's identical to PairEQ. +func Pair(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEQ(FieldPair, v)) +} + // BlockEQ applies the EQ predicate on the "block" field. func BlockEQ(v uint64) predicate.AssetPrice { return predicate.AssetPrice(sql.FieldEQ(FieldBlock, v)) @@ -321,27 +336,229 @@ func SignatureLTE(v []byte) predicate.AssetPrice { return predicate.AssetPrice(sql.FieldLTE(FieldSignature, v)) } -// HasDataSet applies the HasEdge predicate on the "dataSet" edge. -func HasDataSet() predicate.AssetPrice { - return predicate.AssetPrice(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, DataSetTable, DataSetPrimaryKey...), - ) - sqlgraph.HasNeighbors(s, step) - }) +// AssetEQ applies the EQ predicate on the "asset" field. +func AssetEQ(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEQ(FieldAsset, v)) } -// HasDataSetWith applies the HasEdge predicate on the "dataSet" edge with a given conditions (other predicates). -func HasDataSetWith(preds ...predicate.DataSet) predicate.AssetPrice { - return predicate.AssetPrice(func(s *sql.Selector) { - step := newDataSetStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) +// AssetNEQ applies the NEQ predicate on the "asset" field. +func AssetNEQ(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNEQ(FieldAsset, v)) +} + +// AssetIn applies the In predicate on the "asset" field. +func AssetIn(vs ...string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldIn(FieldAsset, vs...)) +} + +// AssetNotIn applies the NotIn predicate on the "asset" field. +func AssetNotIn(vs ...string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNotIn(FieldAsset, vs...)) +} + +// AssetGT applies the GT predicate on the "asset" field. +func AssetGT(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldGT(FieldAsset, v)) +} + +// AssetGTE applies the GTE predicate on the "asset" field. +func AssetGTE(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldGTE(FieldAsset, v)) +} + +// AssetLT applies the LT predicate on the "asset" field. +func AssetLT(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldLT(FieldAsset, v)) +} + +// AssetLTE applies the LTE predicate on the "asset" field. +func AssetLTE(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldLTE(FieldAsset, v)) +} + +// AssetContains applies the Contains predicate on the "asset" field. +func AssetContains(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldContains(FieldAsset, v)) +} + +// AssetHasPrefix applies the HasPrefix predicate on the "asset" field. +func AssetHasPrefix(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldHasPrefix(FieldAsset, v)) +} + +// AssetHasSuffix applies the HasSuffix predicate on the "asset" field. +func AssetHasSuffix(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldHasSuffix(FieldAsset, v)) +} + +// AssetIsNil applies the IsNil predicate on the "asset" field. +func AssetIsNil() predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldIsNull(FieldAsset)) +} + +// AssetNotNil applies the NotNil predicate on the "asset" field. +func AssetNotNil() predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNotNull(FieldAsset)) +} + +// AssetEqualFold applies the EqualFold predicate on the "asset" field. +func AssetEqualFold(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEqualFold(FieldAsset, v)) +} + +// AssetContainsFold applies the ContainsFold predicate on the "asset" field. +func AssetContainsFold(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldContainsFold(FieldAsset, v)) +} + +// ChainEQ applies the EQ predicate on the "chain" field. +func ChainEQ(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEQ(FieldChain, v)) +} + +// ChainNEQ applies the NEQ predicate on the "chain" field. +func ChainNEQ(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNEQ(FieldChain, v)) +} + +// ChainIn applies the In predicate on the "chain" field. +func ChainIn(vs ...string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldIn(FieldChain, vs...)) +} + +// ChainNotIn applies the NotIn predicate on the "chain" field. +func ChainNotIn(vs ...string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNotIn(FieldChain, vs...)) +} + +// ChainGT applies the GT predicate on the "chain" field. +func ChainGT(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldGT(FieldChain, v)) +} + +// ChainGTE applies the GTE predicate on the "chain" field. +func ChainGTE(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldGTE(FieldChain, v)) +} + +// ChainLT applies the LT predicate on the "chain" field. +func ChainLT(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldLT(FieldChain, v)) +} + +// ChainLTE applies the LTE predicate on the "chain" field. +func ChainLTE(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldLTE(FieldChain, v)) +} + +// ChainContains applies the Contains predicate on the "chain" field. +func ChainContains(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldContains(FieldChain, v)) +} + +// ChainHasPrefix applies the HasPrefix predicate on the "chain" field. +func ChainHasPrefix(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldHasPrefix(FieldChain, v)) +} + +// ChainHasSuffix applies the HasSuffix predicate on the "chain" field. +func ChainHasSuffix(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldHasSuffix(FieldChain, v)) +} + +// ChainIsNil applies the IsNil predicate on the "chain" field. +func ChainIsNil() predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldIsNull(FieldChain)) +} + +// ChainNotNil applies the NotNil predicate on the "chain" field. +func ChainNotNil() predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNotNull(FieldChain)) +} + +// ChainEqualFold applies the EqualFold predicate on the "chain" field. +func ChainEqualFold(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEqualFold(FieldChain, v)) +} + +// ChainContainsFold applies the ContainsFold predicate on the "chain" field. +func ChainContainsFold(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldContainsFold(FieldChain, v)) +} + +// PairEQ applies the EQ predicate on the "pair" field. +func PairEQ(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEQ(FieldPair, v)) +} + +// PairNEQ applies the NEQ predicate on the "pair" field. +func PairNEQ(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNEQ(FieldPair, v)) +} + +// PairIn applies the In predicate on the "pair" field. +func PairIn(vs ...string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldIn(FieldPair, vs...)) +} + +// PairNotIn applies the NotIn predicate on the "pair" field. +func PairNotIn(vs ...string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNotIn(FieldPair, vs...)) +} + +// PairGT applies the GT predicate on the "pair" field. +func PairGT(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldGT(FieldPair, v)) +} + +// PairGTE applies the GTE predicate on the "pair" field. +func PairGTE(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldGTE(FieldPair, v)) +} + +// PairLT applies the LT predicate on the "pair" field. +func PairLT(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldLT(FieldPair, v)) +} + +// PairLTE applies the LTE predicate on the "pair" field. +func PairLTE(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldLTE(FieldPair, v)) +} + +// PairContains applies the Contains predicate on the "pair" field. +func PairContains(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldContains(FieldPair, v)) +} + +// PairHasPrefix applies the HasPrefix predicate on the "pair" field. +func PairHasPrefix(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldHasPrefix(FieldPair, v)) +} + +// PairHasSuffix applies the HasSuffix predicate on the "pair" field. +func PairHasSuffix(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldHasSuffix(FieldPair, v)) +} + +// PairIsNil applies the IsNil predicate on the "pair" field. +func PairIsNil() predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldIsNull(FieldPair)) +} + +// PairNotNil applies the NotNil predicate on the "pair" field. +func PairNotNil() predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldNotNull(FieldPair)) +} + +// PairEqualFold applies the EqualFold predicate on the "pair" field. +func PairEqualFold(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldEqualFold(FieldPair, v)) +} + +// PairContainsFold applies the ContainsFold predicate on the "pair" field. +func PairContainsFold(v string) predicate.AssetPrice { + return predicate.AssetPrice(sql.FieldContainsFold(FieldPair, v)) } // HasSigners applies the HasEdge predicate on the "signers" edge. diff --git a/src/ent/assetprice_create.go b/src/ent/assetprice_create.go index 38bc9aca..08ad98d2 100644 --- a/src/ent/assetprice_create.go +++ b/src/ent/assetprice_create.go @@ -12,7 +12,6 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" "github.com/KenshiTech/unchained/ent/signer" ) @@ -56,19 +55,46 @@ func (apc *AssetPriceCreate) SetSignature(b []byte) *AssetPriceCreate { return apc } -// AddDataSetIDs adds the "dataSet" edge to the DataSet entity by IDs. -func (apc *AssetPriceCreate) AddDataSetIDs(ids ...int) *AssetPriceCreate { - apc.mutation.AddDataSetIDs(ids...) +// SetAsset sets the "asset" field. +func (apc *AssetPriceCreate) SetAsset(s string) *AssetPriceCreate { + apc.mutation.SetAsset(s) return apc } -// AddDataSet adds the "dataSet" edges to the DataSet entity. -func (apc *AssetPriceCreate) AddDataSet(d ...*DataSet) *AssetPriceCreate { - ids := make([]int, len(d)) - for i := range d { - ids[i] = d[i].ID +// SetNillableAsset sets the "asset" field if the given value is not nil. +func (apc *AssetPriceCreate) SetNillableAsset(s *string) *AssetPriceCreate { + if s != nil { + apc.SetAsset(*s) } - return apc.AddDataSetIDs(ids...) + return apc +} + +// SetChain sets the "chain" field. +func (apc *AssetPriceCreate) SetChain(s string) *AssetPriceCreate { + apc.mutation.SetChain(s) + return apc +} + +// SetNillableChain sets the "chain" field if the given value is not nil. +func (apc *AssetPriceCreate) SetNillableChain(s *string) *AssetPriceCreate { + if s != nil { + apc.SetChain(*s) + } + return apc +} + +// SetPair sets the "pair" field. +func (apc *AssetPriceCreate) SetPair(s string) *AssetPriceCreate { + apc.mutation.SetPair(s) + return apc +} + +// SetNillablePair sets the "pair" field if the given value is not nil. +func (apc *AssetPriceCreate) SetNillablePair(s *string) *AssetPriceCreate { + if s != nil { + apc.SetPair(*s) + } + return apc } // AddSignerIDs adds the "signers" edge to the Signer entity by IDs. @@ -134,9 +160,6 @@ func (apc *AssetPriceCreate) check() error { return &ValidationError{Name: "signature", err: fmt.Errorf(`ent: validator failed for field "AssetPrice.signature": %w`, err)} } } - if len(apc.mutation.DataSetIDs()) == 0 { - return &ValidationError{Name: "dataSet", err: errors.New(`ent: missing required edge "AssetPrice.dataSet"`)} - } if len(apc.mutation.SignersIDs()) == 0 { return &ValidationError{Name: "signers", err: errors.New(`ent: missing required edge "AssetPrice.signers"`)} } @@ -190,21 +213,17 @@ func (apc *AssetPriceCreate) createSpec() (*AssetPrice, *sqlgraph.CreateSpec, er _spec.SetField(assetprice.FieldSignature, field.TypeBytes, value) _node.Signature = value } - if nodes := apc.mutation.DataSetIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: assetprice.DataSetTable, - Columns: assetprice.DataSetPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) + if value, ok := apc.mutation.Asset(); ok { + _spec.SetField(assetprice.FieldAsset, field.TypeString, value) + _node.Asset = value + } + if value, ok := apc.mutation.Chain(); ok { + _spec.SetField(assetprice.FieldChain, field.TypeString, value) + _node.Chain = value + } + if value, ok := apc.mutation.Pair(); ok { + _spec.SetField(assetprice.FieldPair, field.TypeString, value) + _node.Pair = value } if nodes := apc.mutation.SignersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ @@ -340,6 +359,60 @@ func (u *AssetPriceUpsert) UpdateSignature() *AssetPriceUpsert { return u } +// SetAsset sets the "asset" field. +func (u *AssetPriceUpsert) SetAsset(v string) *AssetPriceUpsert { + u.Set(assetprice.FieldAsset, v) + return u +} + +// UpdateAsset sets the "asset" field to the value that was provided on create. +func (u *AssetPriceUpsert) UpdateAsset() *AssetPriceUpsert { + u.SetExcluded(assetprice.FieldAsset) + return u +} + +// ClearAsset clears the value of the "asset" field. +func (u *AssetPriceUpsert) ClearAsset() *AssetPriceUpsert { + u.SetNull(assetprice.FieldAsset) + return u +} + +// SetChain sets the "chain" field. +func (u *AssetPriceUpsert) SetChain(v string) *AssetPriceUpsert { + u.Set(assetprice.FieldChain, v) + return u +} + +// UpdateChain sets the "chain" field to the value that was provided on create. +func (u *AssetPriceUpsert) UpdateChain() *AssetPriceUpsert { + u.SetExcluded(assetprice.FieldChain) + return u +} + +// ClearChain clears the value of the "chain" field. +func (u *AssetPriceUpsert) ClearChain() *AssetPriceUpsert { + u.SetNull(assetprice.FieldChain) + return u +} + +// SetPair sets the "pair" field. +func (u *AssetPriceUpsert) SetPair(v string) *AssetPriceUpsert { + u.Set(assetprice.FieldPair, v) + return u +} + +// UpdatePair sets the "pair" field to the value that was provided on create. +func (u *AssetPriceUpsert) UpdatePair() *AssetPriceUpsert { + u.SetExcluded(assetprice.FieldPair) + return u +} + +// ClearPair clears the value of the "pair" field. +func (u *AssetPriceUpsert) ClearPair() *AssetPriceUpsert { + u.SetNull(assetprice.FieldPair) + return u +} + // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // @@ -457,6 +530,69 @@ func (u *AssetPriceUpsertOne) UpdateSignature() *AssetPriceUpsertOne { }) } +// SetAsset sets the "asset" field. +func (u *AssetPriceUpsertOne) SetAsset(v string) *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.SetAsset(v) + }) +} + +// UpdateAsset sets the "asset" field to the value that was provided on create. +func (u *AssetPriceUpsertOne) UpdateAsset() *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.UpdateAsset() + }) +} + +// ClearAsset clears the value of the "asset" field. +func (u *AssetPriceUpsertOne) ClearAsset() *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.ClearAsset() + }) +} + +// SetChain sets the "chain" field. +func (u *AssetPriceUpsertOne) SetChain(v string) *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.SetChain(v) + }) +} + +// UpdateChain sets the "chain" field to the value that was provided on create. +func (u *AssetPriceUpsertOne) UpdateChain() *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.UpdateChain() + }) +} + +// ClearChain clears the value of the "chain" field. +func (u *AssetPriceUpsertOne) ClearChain() *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.ClearChain() + }) +} + +// SetPair sets the "pair" field. +func (u *AssetPriceUpsertOne) SetPair(v string) *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.SetPair(v) + }) +} + +// UpdatePair sets the "pair" field to the value that was provided on create. +func (u *AssetPriceUpsertOne) UpdatePair() *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.UpdatePair() + }) +} + +// ClearPair clears the value of the "pair" field. +func (u *AssetPriceUpsertOne) ClearPair() *AssetPriceUpsertOne { + return u.Update(func(s *AssetPriceUpsert) { + s.ClearPair() + }) +} + // Exec executes the query. func (u *AssetPriceUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { @@ -740,6 +876,69 @@ func (u *AssetPriceUpsertBulk) UpdateSignature() *AssetPriceUpsertBulk { }) } +// SetAsset sets the "asset" field. +func (u *AssetPriceUpsertBulk) SetAsset(v string) *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.SetAsset(v) + }) +} + +// UpdateAsset sets the "asset" field to the value that was provided on create. +func (u *AssetPriceUpsertBulk) UpdateAsset() *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.UpdateAsset() + }) +} + +// ClearAsset clears the value of the "asset" field. +func (u *AssetPriceUpsertBulk) ClearAsset() *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.ClearAsset() + }) +} + +// SetChain sets the "chain" field. +func (u *AssetPriceUpsertBulk) SetChain(v string) *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.SetChain(v) + }) +} + +// UpdateChain sets the "chain" field to the value that was provided on create. +func (u *AssetPriceUpsertBulk) UpdateChain() *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.UpdateChain() + }) +} + +// ClearChain clears the value of the "chain" field. +func (u *AssetPriceUpsertBulk) ClearChain() *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.ClearChain() + }) +} + +// SetPair sets the "pair" field. +func (u *AssetPriceUpsertBulk) SetPair(v string) *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.SetPair(v) + }) +} + +// UpdatePair sets the "pair" field to the value that was provided on create. +func (u *AssetPriceUpsertBulk) UpdatePair() *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.UpdatePair() + }) +} + +// ClearPair clears the value of the "pair" field. +func (u *AssetPriceUpsertBulk) ClearPair() *AssetPriceUpsertBulk { + return u.Update(func(s *AssetPriceUpsert) { + s.ClearPair() + }) +} + // Exec executes the query. func (u *AssetPriceUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { diff --git a/src/ent/assetprice_query.go b/src/ent/assetprice_query.go index 7c9b2f16..6c2c4777 100644 --- a/src/ent/assetprice_query.go +++ b/src/ent/assetprice_query.go @@ -12,7 +12,6 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" "github.com/KenshiTech/unchained/ent/predicate" "github.com/KenshiTech/unchained/ent/signer" ) @@ -24,7 +23,6 @@ type AssetPriceQuery struct { order []assetprice.OrderOption inters []Interceptor predicates []predicate.AssetPrice - withDataSet *DataSetQuery withSigners *SignerQuery // intermediate query (i.e. traversal path). sql *sql.Selector @@ -62,28 +60,6 @@ func (apq *AssetPriceQuery) Order(o ...assetprice.OrderOption) *AssetPriceQuery return apq } -// QueryDataSet chains the current query on the "dataSet" edge. -func (apq *AssetPriceQuery) QueryDataSet() *DataSetQuery { - query := (&DataSetClient{config: apq.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := apq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := apq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(assetprice.Table, assetprice.FieldID, selector), - sqlgraph.To(dataset.Table, dataset.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, assetprice.DataSetTable, assetprice.DataSetPrimaryKey...), - ) - fromU = sqlgraph.SetNeighbors(apq.driver.Dialect(), step) - return fromU, nil - } - return query -} - // QuerySigners chains the current query on the "signers" edge. func (apq *AssetPriceQuery) QuerySigners() *SignerQuery { query := (&SignerClient{config: apq.config}).Query() @@ -298,7 +274,6 @@ func (apq *AssetPriceQuery) Clone() *AssetPriceQuery { order: append([]assetprice.OrderOption{}, apq.order...), inters: append([]Interceptor{}, apq.inters...), predicates: append([]predicate.AssetPrice{}, apq.predicates...), - withDataSet: apq.withDataSet.Clone(), withSigners: apq.withSigners.Clone(), // clone intermediate query. sql: apq.sql.Clone(), @@ -306,17 +281,6 @@ func (apq *AssetPriceQuery) Clone() *AssetPriceQuery { } } -// WithDataSet tells the query-builder to eager-load the nodes that are connected to -// the "dataSet" edge. The optional arguments are used to configure the query builder of the edge. -func (apq *AssetPriceQuery) WithDataSet(opts ...func(*DataSetQuery)) *AssetPriceQuery { - query := (&DataSetClient{config: apq.config}).Query() - for _, opt := range opts { - opt(query) - } - apq.withDataSet = query - return apq -} - // WithSigners tells the query-builder to eager-load the nodes that are connected to // the "signers" edge. The optional arguments are used to configure the query builder of the edge. func (apq *AssetPriceQuery) WithSigners(opts ...func(*SignerQuery)) *AssetPriceQuery { @@ -406,8 +370,7 @@ func (apq *AssetPriceQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]* var ( nodes = []*AssetPrice{} _spec = apq.querySpec() - loadedTypes = [2]bool{ - apq.withDataSet != nil, + loadedTypes = [1]bool{ apq.withSigners != nil, } ) @@ -429,13 +392,6 @@ func (apq *AssetPriceQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]* if len(nodes) == 0 { return nodes, nil } - if query := apq.withDataSet; query != nil { - if err := apq.loadDataSet(ctx, query, nodes, - func(n *AssetPrice) { n.Edges.DataSet = []*DataSet{} }, - func(n *AssetPrice, e *DataSet) { n.Edges.DataSet = append(n.Edges.DataSet, e) }); err != nil { - return nil, err - } - } if query := apq.withSigners; query != nil { if err := apq.loadSigners(ctx, query, nodes, func(n *AssetPrice) { n.Edges.Signers = []*Signer{} }, @@ -446,67 +402,6 @@ func (apq *AssetPriceQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]* return nodes, nil } -func (apq *AssetPriceQuery) loadDataSet(ctx context.Context, query *DataSetQuery, nodes []*AssetPrice, init func(*AssetPrice), assign func(*AssetPrice, *DataSet)) error { - edgeIDs := make([]driver.Value, len(nodes)) - byID := make(map[int]*AssetPrice) - nids := make(map[int]map[*AssetPrice]struct{}) - for i, node := range nodes { - edgeIDs[i] = node.ID - byID[node.ID] = node - if init != nil { - init(node) - } - } - query.Where(func(s *sql.Selector) { - joinT := sql.Table(assetprice.DataSetTable) - s.Join(joinT).On(s.C(dataset.FieldID), joinT.C(assetprice.DataSetPrimaryKey[1])) - s.Where(sql.InValues(joinT.C(assetprice.DataSetPrimaryKey[0]), edgeIDs...)) - columns := s.SelectedColumns() - s.Select(joinT.C(assetprice.DataSetPrimaryKey[0])) - s.AppendSelect(columns...) - s.SetDistinct(false) - }) - if err := query.prepareQuery(ctx); err != nil { - return err - } - qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { - assign := spec.Assign - values := spec.ScanValues - spec.ScanValues = func(columns []string) ([]any, error) { - values, err := values(columns[1:]) - if err != nil { - return nil, err - } - return append([]any{new(sql.NullInt64)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := int(values[0].(*sql.NullInt64).Int64) - inValue := int(values[1].(*sql.NullInt64).Int64) - if nids[inValue] == nil { - nids[inValue] = map[*AssetPrice]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) - } - nids[inValue][byID[outValue]] = struct{}{} - return nil - } - }) - }) - neighbors, err := withInterceptors[[]*DataSet](ctx, query, qr, query.inters) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nids[n.ID] - if !ok { - return fmt.Errorf(`unexpected "dataSet" node returned %v`, n.ID) - } - for kn := range nodes { - assign(kn, n) - } - } - return nil -} func (apq *AssetPriceQuery) loadSigners(ctx context.Context, query *SignerQuery, nodes []*AssetPrice, init func(*AssetPrice), assign func(*AssetPrice, *Signer)) error { edgeIDs := make([]driver.Value, len(nodes)) byID := make(map[int]*AssetPrice) diff --git a/src/ent/assetprice_update.go b/src/ent/assetprice_update.go index 072d9575..b8ad3cea 100644 --- a/src/ent/assetprice_update.go +++ b/src/ent/assetprice_update.go @@ -12,7 +12,6 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" "github.com/KenshiTech/unchained/ent/predicate" "github.com/KenshiTech/unchained/ent/signer" ) @@ -90,19 +89,64 @@ func (apu *AssetPriceUpdate) SetSignature(b []byte) *AssetPriceUpdate { return apu } -// AddDataSetIDs adds the "dataSet" edge to the DataSet entity by IDs. -func (apu *AssetPriceUpdate) AddDataSetIDs(ids ...int) *AssetPriceUpdate { - apu.mutation.AddDataSetIDs(ids...) +// SetAsset sets the "asset" field. +func (apu *AssetPriceUpdate) SetAsset(s string) *AssetPriceUpdate { + apu.mutation.SetAsset(s) return apu } -// AddDataSet adds the "dataSet" edges to the DataSet entity. -func (apu *AssetPriceUpdate) AddDataSet(d ...*DataSet) *AssetPriceUpdate { - ids := make([]int, len(d)) - for i := range d { - ids[i] = d[i].ID +// SetNillableAsset sets the "asset" field if the given value is not nil. +func (apu *AssetPriceUpdate) SetNillableAsset(s *string) *AssetPriceUpdate { + if s != nil { + apu.SetAsset(*s) } - return apu.AddDataSetIDs(ids...) + return apu +} + +// ClearAsset clears the value of the "asset" field. +func (apu *AssetPriceUpdate) ClearAsset() *AssetPriceUpdate { + apu.mutation.ClearAsset() + return apu +} + +// SetChain sets the "chain" field. +func (apu *AssetPriceUpdate) SetChain(s string) *AssetPriceUpdate { + apu.mutation.SetChain(s) + return apu +} + +// SetNillableChain sets the "chain" field if the given value is not nil. +func (apu *AssetPriceUpdate) SetNillableChain(s *string) *AssetPriceUpdate { + if s != nil { + apu.SetChain(*s) + } + return apu +} + +// ClearChain clears the value of the "chain" field. +func (apu *AssetPriceUpdate) ClearChain() *AssetPriceUpdate { + apu.mutation.ClearChain() + return apu +} + +// SetPair sets the "pair" field. +func (apu *AssetPriceUpdate) SetPair(s string) *AssetPriceUpdate { + apu.mutation.SetPair(s) + return apu +} + +// SetNillablePair sets the "pair" field if the given value is not nil. +func (apu *AssetPriceUpdate) SetNillablePair(s *string) *AssetPriceUpdate { + if s != nil { + apu.SetPair(*s) + } + return apu +} + +// ClearPair clears the value of the "pair" field. +func (apu *AssetPriceUpdate) ClearPair() *AssetPriceUpdate { + apu.mutation.ClearPair() + return apu } // AddSignerIDs adds the "signers" edge to the Signer entity by IDs. @@ -125,27 +169,6 @@ func (apu *AssetPriceUpdate) Mutation() *AssetPriceMutation { return apu.mutation } -// ClearDataSet clears all "dataSet" edges to the DataSet entity. -func (apu *AssetPriceUpdate) ClearDataSet() *AssetPriceUpdate { - apu.mutation.ClearDataSet() - return apu -} - -// RemoveDataSetIDs removes the "dataSet" edge to DataSet entities by IDs. -func (apu *AssetPriceUpdate) RemoveDataSetIDs(ids ...int) *AssetPriceUpdate { - apu.mutation.RemoveDataSetIDs(ids...) - return apu -} - -// RemoveDataSet removes "dataSet" edges to DataSet entities. -func (apu *AssetPriceUpdate) RemoveDataSet(d ...*DataSet) *AssetPriceUpdate { - ids := make([]int, len(d)) - for i := range d { - ids[i] = d[i].ID - } - return apu.RemoveDataSetIDs(ids...) -} - // ClearSigners clears all "signers" edges to the Signer entity. func (apu *AssetPriceUpdate) ClearSigners() *AssetPriceUpdate { apu.mutation.ClearSigners() @@ -241,50 +264,23 @@ func (apu *AssetPriceUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := apu.mutation.Signature(); ok { _spec.SetField(assetprice.FieldSignature, field.TypeBytes, value) } - if apu.mutation.DataSetCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: assetprice.DataSetTable, - Columns: assetprice.DataSetPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + if value, ok := apu.mutation.Asset(); ok { + _spec.SetField(assetprice.FieldAsset, field.TypeString, value) } - if nodes := apu.mutation.RemovedDataSetIDs(); len(nodes) > 0 && !apu.mutation.DataSetCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: assetprice.DataSetTable, - Columns: assetprice.DataSetPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + if apu.mutation.AssetCleared() { + _spec.ClearField(assetprice.FieldAsset, field.TypeString) } - if nodes := apu.mutation.DataSetIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: assetprice.DataSetTable, - Columns: assetprice.DataSetPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) + if value, ok := apu.mutation.Chain(); ok { + _spec.SetField(assetprice.FieldChain, field.TypeString, value) + } + if apu.mutation.ChainCleared() { + _spec.ClearField(assetprice.FieldChain, field.TypeString) + } + if value, ok := apu.mutation.Pair(); ok { + _spec.SetField(assetprice.FieldPair, field.TypeString, value) + } + if apu.mutation.PairCleared() { + _spec.ClearField(assetprice.FieldPair, field.TypeString) } if apu.mutation.SignersCleared() { edge := &sqlgraph.EdgeSpec{ @@ -411,19 +407,64 @@ func (apuo *AssetPriceUpdateOne) SetSignature(b []byte) *AssetPriceUpdateOne { return apuo } -// AddDataSetIDs adds the "dataSet" edge to the DataSet entity by IDs. -func (apuo *AssetPriceUpdateOne) AddDataSetIDs(ids ...int) *AssetPriceUpdateOne { - apuo.mutation.AddDataSetIDs(ids...) +// SetAsset sets the "asset" field. +func (apuo *AssetPriceUpdateOne) SetAsset(s string) *AssetPriceUpdateOne { + apuo.mutation.SetAsset(s) return apuo } -// AddDataSet adds the "dataSet" edges to the DataSet entity. -func (apuo *AssetPriceUpdateOne) AddDataSet(d ...*DataSet) *AssetPriceUpdateOne { - ids := make([]int, len(d)) - for i := range d { - ids[i] = d[i].ID +// SetNillableAsset sets the "asset" field if the given value is not nil. +func (apuo *AssetPriceUpdateOne) SetNillableAsset(s *string) *AssetPriceUpdateOne { + if s != nil { + apuo.SetAsset(*s) } - return apuo.AddDataSetIDs(ids...) + return apuo +} + +// ClearAsset clears the value of the "asset" field. +func (apuo *AssetPriceUpdateOne) ClearAsset() *AssetPriceUpdateOne { + apuo.mutation.ClearAsset() + return apuo +} + +// SetChain sets the "chain" field. +func (apuo *AssetPriceUpdateOne) SetChain(s string) *AssetPriceUpdateOne { + apuo.mutation.SetChain(s) + return apuo +} + +// SetNillableChain sets the "chain" field if the given value is not nil. +func (apuo *AssetPriceUpdateOne) SetNillableChain(s *string) *AssetPriceUpdateOne { + if s != nil { + apuo.SetChain(*s) + } + return apuo +} + +// ClearChain clears the value of the "chain" field. +func (apuo *AssetPriceUpdateOne) ClearChain() *AssetPriceUpdateOne { + apuo.mutation.ClearChain() + return apuo +} + +// SetPair sets the "pair" field. +func (apuo *AssetPriceUpdateOne) SetPair(s string) *AssetPriceUpdateOne { + apuo.mutation.SetPair(s) + return apuo +} + +// SetNillablePair sets the "pair" field if the given value is not nil. +func (apuo *AssetPriceUpdateOne) SetNillablePair(s *string) *AssetPriceUpdateOne { + if s != nil { + apuo.SetPair(*s) + } + return apuo +} + +// ClearPair clears the value of the "pair" field. +func (apuo *AssetPriceUpdateOne) ClearPair() *AssetPriceUpdateOne { + apuo.mutation.ClearPair() + return apuo } // AddSignerIDs adds the "signers" edge to the Signer entity by IDs. @@ -446,27 +487,6 @@ func (apuo *AssetPriceUpdateOne) Mutation() *AssetPriceMutation { return apuo.mutation } -// ClearDataSet clears all "dataSet" edges to the DataSet entity. -func (apuo *AssetPriceUpdateOne) ClearDataSet() *AssetPriceUpdateOne { - apuo.mutation.ClearDataSet() - return apuo -} - -// RemoveDataSetIDs removes the "dataSet" edge to DataSet entities by IDs. -func (apuo *AssetPriceUpdateOne) RemoveDataSetIDs(ids ...int) *AssetPriceUpdateOne { - apuo.mutation.RemoveDataSetIDs(ids...) - return apuo -} - -// RemoveDataSet removes "dataSet" edges to DataSet entities. -func (apuo *AssetPriceUpdateOne) RemoveDataSet(d ...*DataSet) *AssetPriceUpdateOne { - ids := make([]int, len(d)) - for i := range d { - ids[i] = d[i].ID - } - return apuo.RemoveDataSetIDs(ids...) -} - // ClearSigners clears all "signers" edges to the Signer entity. func (apuo *AssetPriceUpdateOne) ClearSigners() *AssetPriceUpdateOne { apuo.mutation.ClearSigners() @@ -592,50 +612,23 @@ func (apuo *AssetPriceUpdateOne) sqlSave(ctx context.Context) (_node *AssetPrice if value, ok := apuo.mutation.Signature(); ok { _spec.SetField(assetprice.FieldSignature, field.TypeBytes, value) } - if apuo.mutation.DataSetCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: assetprice.DataSetTable, - Columns: assetprice.DataSetPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + if value, ok := apuo.mutation.Asset(); ok { + _spec.SetField(assetprice.FieldAsset, field.TypeString, value) } - if nodes := apuo.mutation.RemovedDataSetIDs(); len(nodes) > 0 && !apuo.mutation.DataSetCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: assetprice.DataSetTable, - Columns: assetprice.DataSetPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + if apuo.mutation.AssetCleared() { + _spec.ClearField(assetprice.FieldAsset, field.TypeString) } - if nodes := apuo.mutation.DataSetIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: assetprice.DataSetTable, - Columns: assetprice.DataSetPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) + if value, ok := apuo.mutation.Chain(); ok { + _spec.SetField(assetprice.FieldChain, field.TypeString, value) + } + if apuo.mutation.ChainCleared() { + _spec.ClearField(assetprice.FieldChain, field.TypeString) + } + if value, ok := apuo.mutation.Pair(); ok { + _spec.SetField(assetprice.FieldPair, field.TypeString, value) + } + if apuo.mutation.PairCleared() { + _spec.ClearField(assetprice.FieldPair, field.TypeString) } if apuo.mutation.SignersCleared() { edge := &sqlgraph.EdgeSpec{ diff --git a/src/ent/client.go b/src/ent/client.go index cd7c84b4..109fdd56 100644 --- a/src/ent/client.go +++ b/src/ent/client.go @@ -16,7 +16,6 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" "github.com/KenshiTech/unchained/ent/signer" ) @@ -27,8 +26,6 @@ type Client struct { Schema *migrate.Schema // AssetPrice is the client for interacting with the AssetPrice builders. AssetPrice *AssetPriceClient - // DataSet is the client for interacting with the DataSet builders. - DataSet *DataSetClient // Signer is the client for interacting with the Signer builders. Signer *SignerClient } @@ -43,7 +40,6 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) c.AssetPrice = NewAssetPriceClient(c.config) - c.DataSet = NewDataSetClient(c.config) c.Signer = NewSignerClient(c.config) } @@ -138,7 +134,6 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { ctx: ctx, config: cfg, AssetPrice: NewAssetPriceClient(cfg), - DataSet: NewDataSetClient(cfg), Signer: NewSignerClient(cfg), }, nil } @@ -160,7 +155,6 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) ctx: ctx, config: cfg, AssetPrice: NewAssetPriceClient(cfg), - DataSet: NewDataSetClient(cfg), Signer: NewSignerClient(cfg), }, nil } @@ -191,7 +185,6 @@ func (c *Client) Close() error { // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { c.AssetPrice.Use(hooks...) - c.DataSet.Use(hooks...) c.Signer.Use(hooks...) } @@ -199,7 +192,6 @@ func (c *Client) Use(hooks ...Hook) { // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { c.AssetPrice.Intercept(interceptors...) - c.DataSet.Intercept(interceptors...) c.Signer.Intercept(interceptors...) } @@ -208,8 +200,6 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { case *AssetPriceMutation: return c.AssetPrice.mutate(ctx, m) - case *DataSetMutation: - return c.DataSet.mutate(ctx, m) case *SignerMutation: return c.Signer.mutate(ctx, m) default: @@ -325,22 +315,6 @@ func (c *AssetPriceClient) GetX(ctx context.Context, id int) *AssetPrice { return obj } -// QueryDataSet queries the dataSet edge of a AssetPrice. -func (c *AssetPriceClient) QueryDataSet(ap *AssetPrice) *DataSetQuery { - query := (&DataSetClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := ap.ID - step := sqlgraph.NewStep( - sqlgraph.From(assetprice.Table, assetprice.FieldID, id), - sqlgraph.To(dataset.Table, dataset.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, assetprice.DataSetTable, assetprice.DataSetPrimaryKey...), - ) - fromV = sqlgraph.Neighbors(ap.driver.Dialect(), step) - return fromV, nil - } - return query -} - // QuerySigners queries the signers edge of a AssetPrice. func (c *AssetPriceClient) QuerySigners(ap *AssetPrice) *SignerQuery { query := (&SignerClient{config: c.config}).Query() @@ -382,155 +356,6 @@ func (c *AssetPriceClient) mutate(ctx context.Context, m *AssetPriceMutation) (V } } -// DataSetClient is a client for the DataSet schema. -type DataSetClient struct { - config -} - -// NewDataSetClient returns a client for the DataSet from the given config. -func NewDataSetClient(c config) *DataSetClient { - return &DataSetClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `dataset.Hooks(f(g(h())))`. -func (c *DataSetClient) Use(hooks ...Hook) { - c.hooks.DataSet = append(c.hooks.DataSet, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `dataset.Intercept(f(g(h())))`. -func (c *DataSetClient) Intercept(interceptors ...Interceptor) { - c.inters.DataSet = append(c.inters.DataSet, interceptors...) -} - -// Create returns a builder for creating a DataSet entity. -func (c *DataSetClient) Create() *DataSetCreate { - mutation := newDataSetMutation(c.config, OpCreate) - return &DataSetCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of DataSet entities. -func (c *DataSetClient) CreateBulk(builders ...*DataSetCreate) *DataSetCreateBulk { - return &DataSetCreateBulk{config: c.config, builders: builders} -} - -// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates -// a builder and applies setFunc on it. -func (c *DataSetClient) MapCreateBulk(slice any, setFunc func(*DataSetCreate, int)) *DataSetCreateBulk { - rv := reflect.ValueOf(slice) - if rv.Kind() != reflect.Slice { - return &DataSetCreateBulk{err: fmt.Errorf("calling to DataSetClient.MapCreateBulk with wrong type %T, need slice", slice)} - } - builders := make([]*DataSetCreate, rv.Len()) - for i := 0; i < rv.Len(); i++ { - builders[i] = c.Create() - setFunc(builders[i], i) - } - return &DataSetCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for DataSet. -func (c *DataSetClient) Update() *DataSetUpdate { - mutation := newDataSetMutation(c.config, OpUpdate) - return &DataSetUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *DataSetClient) UpdateOne(ds *DataSet) *DataSetUpdateOne { - mutation := newDataSetMutation(c.config, OpUpdateOne, withDataSet(ds)) - return &DataSetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *DataSetClient) UpdateOneID(id int) *DataSetUpdateOne { - mutation := newDataSetMutation(c.config, OpUpdateOne, withDataSetID(id)) - return &DataSetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for DataSet. -func (c *DataSetClient) Delete() *DataSetDelete { - mutation := newDataSetMutation(c.config, OpDelete) - return &DataSetDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *DataSetClient) DeleteOne(ds *DataSet) *DataSetDeleteOne { - return c.DeleteOneID(ds.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *DataSetClient) DeleteOneID(id int) *DataSetDeleteOne { - builder := c.Delete().Where(dataset.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &DataSetDeleteOne{builder} -} - -// Query returns a query builder for DataSet. -func (c *DataSetClient) Query() *DataSetQuery { - return &DataSetQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeDataSet}, - inters: c.Interceptors(), - } -} - -// Get returns a DataSet entity by its id. -func (c *DataSetClient) Get(ctx context.Context, id int) (*DataSet, error) { - return c.Query().Where(dataset.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *DataSetClient) GetX(ctx context.Context, id int) *DataSet { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryAssetPrice queries the assetPrice edge of a DataSet. -func (c *DataSetClient) QueryAssetPrice(ds *DataSet) *AssetPriceQuery { - query := (&AssetPriceClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := ds.ID - step := sqlgraph.NewStep( - sqlgraph.From(dataset.Table, dataset.FieldID, id), - sqlgraph.To(assetprice.Table, assetprice.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, dataset.AssetPriceTable, dataset.AssetPricePrimaryKey...), - ) - fromV = sqlgraph.Neighbors(ds.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *DataSetClient) Hooks() []Hook { - return c.hooks.DataSet -} - -// Interceptors returns the client interceptors. -func (c *DataSetClient) Interceptors() []Interceptor { - return c.inters.DataSet -} - -func (c *DataSetClient) mutate(ctx context.Context, m *DataSetMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&DataSetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&DataSetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&DataSetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&DataSetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown DataSet mutation op: %q", m.Op()) - } -} - // SignerClient is a client for the Signer schema. type SignerClient struct { config @@ -683,9 +508,9 @@ func (c *SignerClient) mutate(ctx context.Context, m *SignerMutation) (Value, er // hooks and interceptors per client, for fast access. type ( hooks struct { - AssetPrice, DataSet, Signer []ent.Hook + AssetPrice, Signer []ent.Hook } inters struct { - AssetPrice, DataSet, Signer []ent.Interceptor + AssetPrice, Signer []ent.Interceptor } ) diff --git a/src/ent/dataset.go b/src/ent/dataset.go deleted file mode 100644 index 860215a1..00000000 --- a/src/ent/dataset.go +++ /dev/null @@ -1,129 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/KenshiTech/unchained/ent/dataset" -) - -// DataSet is the model entity for the DataSet schema. -type DataSet struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the DataSetQuery when eager-loading is set. - Edges DataSetEdges `json:"edges"` - selectValues sql.SelectValues -} - -// DataSetEdges holds the relations/edges for other nodes in the graph. -type DataSetEdges struct { - // AssetPrice holds the value of the assetPrice edge. - AssetPrice []*AssetPrice `json:"assetPrice,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// AssetPriceOrErr returns the AssetPrice value or an error if the edge -// was not loaded in eager-loading. -func (e DataSetEdges) AssetPriceOrErr() ([]*AssetPrice, error) { - if e.loadedTypes[0] { - return e.AssetPrice, nil - } - return nil, &NotLoadedError{edge: "assetPrice"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*DataSet) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case dataset.FieldID: - values[i] = new(sql.NullInt64) - case dataset.FieldName: - values[i] = new(sql.NullString) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the DataSet fields. -func (ds *DataSet) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case dataset.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - ds.ID = int(value.Int64) - case dataset.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - ds.Name = value.String - } - default: - ds.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the DataSet. -// This includes values selected through modifiers, order, etc. -func (ds *DataSet) Value(name string) (ent.Value, error) { - return ds.selectValues.Get(name) -} - -// QueryAssetPrice queries the "assetPrice" edge of the DataSet entity. -func (ds *DataSet) QueryAssetPrice() *AssetPriceQuery { - return NewDataSetClient(ds.config).QueryAssetPrice(ds) -} - -// Update returns a builder for updating this DataSet. -// Note that you need to call DataSet.Unwrap() before calling this method if this DataSet -// was returned from a transaction, and the transaction was committed or rolled back. -func (ds *DataSet) Update() *DataSetUpdateOne { - return NewDataSetClient(ds.config).UpdateOne(ds) -} - -// Unwrap unwraps the DataSet entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (ds *DataSet) Unwrap() *DataSet { - _tx, ok := ds.config.driver.(*txDriver) - if !ok { - panic("ent: DataSet is not a transactional entity") - } - ds.config.driver = _tx.drv - return ds -} - -// String implements the fmt.Stringer. -func (ds *DataSet) String() string { - var builder strings.Builder - builder.WriteString("DataSet(") - builder.WriteString(fmt.Sprintf("id=%v, ", ds.ID)) - builder.WriteString("name=") - builder.WriteString(ds.Name) - builder.WriteByte(')') - return builder.String() -} - -// DataSets is a parsable slice of DataSet. -type DataSets []*DataSet diff --git a/src/ent/dataset/dataset.go b/src/ent/dataset/dataset.go deleted file mode 100644 index e4859f23..00000000 --- a/src/ent/dataset/dataset.go +++ /dev/null @@ -1,87 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package dataset - -import ( - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -const ( - // Label holds the string label denoting the dataset type in the database. - Label = "data_set" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldName holds the string denoting the name field in the database. - FieldName = "name" - // EdgeAssetPrice holds the string denoting the assetprice edge name in mutations. - EdgeAssetPrice = "assetPrice" - // Table holds the table name of the dataset in the database. - Table = "data_sets" - // AssetPriceTable is the table that holds the assetPrice relation/edge. The primary key declared below. - AssetPriceTable = "asset_price_dataSet" - // AssetPriceInverseTable is the table name for the AssetPrice entity. - // It exists in this package in order to avoid circular dependency with the "assetprice" package. - AssetPriceInverseTable = "asset_prices" -) - -// Columns holds all SQL columns for dataset fields. -var Columns = []string{ - FieldID, - FieldName, -} - -var ( - // AssetPricePrimaryKey and AssetPriceColumn2 are the table columns denoting the - // primary key for the assetPrice relation (M2M). - AssetPricePrimaryKey = []string{"asset_price_id", "data_set_id"} -) - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // NameValidator is a validator for the "name" field. It is called by the builders before save. - NameValidator func(string) error -) - -// OrderOption defines the ordering options for the DataSet queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByName orders the results by the name field. -func ByName(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldName, opts...).ToFunc() -} - -// ByAssetPriceCount orders the results by assetPrice count. -func ByAssetPriceCount(opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newAssetPriceStep(), opts...) - } -} - -// ByAssetPrice orders the results by assetPrice terms. -func ByAssetPrice(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newAssetPriceStep(), append([]sql.OrderTerm{term}, terms...)...) - } -} -func newAssetPriceStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(AssetPriceInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, AssetPriceTable, AssetPricePrimaryKey...), - ) -} diff --git a/src/ent/dataset/where.go b/src/ent/dataset/where.go deleted file mode 100644 index ed942c04..00000000 --- a/src/ent/dataset/where.go +++ /dev/null @@ -1,162 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package dataset - -import ( - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/KenshiTech/unchained/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.DataSet { - return predicate.DataSet(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.DataSet { - return predicate.DataSet(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.DataSet { - return predicate.DataSet(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.DataSet { - return predicate.DataSet(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.DataSet { - return predicate.DataSet(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.DataSet { - return predicate.DataSet(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.DataSet { - return predicate.DataSet(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.DataSet { - return predicate.DataSet(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.DataSet { - return predicate.DataSet(sql.FieldLTE(FieldID, id)) -} - -// Name applies equality check predicate on the "name" field. It's identical to NameEQ. -func Name(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldEQ(FieldName, v)) -} - -// NameEQ applies the EQ predicate on the "name" field. -func NameEQ(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldEQ(FieldName, v)) -} - -// NameNEQ applies the NEQ predicate on the "name" field. -func NameNEQ(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldNEQ(FieldName, v)) -} - -// NameIn applies the In predicate on the "name" field. -func NameIn(vs ...string) predicate.DataSet { - return predicate.DataSet(sql.FieldIn(FieldName, vs...)) -} - -// NameNotIn applies the NotIn predicate on the "name" field. -func NameNotIn(vs ...string) predicate.DataSet { - return predicate.DataSet(sql.FieldNotIn(FieldName, vs...)) -} - -// NameGT applies the GT predicate on the "name" field. -func NameGT(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldGT(FieldName, v)) -} - -// NameGTE applies the GTE predicate on the "name" field. -func NameGTE(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldGTE(FieldName, v)) -} - -// NameLT applies the LT predicate on the "name" field. -func NameLT(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldLT(FieldName, v)) -} - -// NameLTE applies the LTE predicate on the "name" field. -func NameLTE(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldLTE(FieldName, v)) -} - -// NameContains applies the Contains predicate on the "name" field. -func NameContains(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldContains(FieldName, v)) -} - -// NameHasPrefix applies the HasPrefix predicate on the "name" field. -func NameHasPrefix(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldHasPrefix(FieldName, v)) -} - -// NameHasSuffix applies the HasSuffix predicate on the "name" field. -func NameHasSuffix(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldHasSuffix(FieldName, v)) -} - -// NameEqualFold applies the EqualFold predicate on the "name" field. -func NameEqualFold(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldEqualFold(FieldName, v)) -} - -// NameContainsFold applies the ContainsFold predicate on the "name" field. -func NameContainsFold(v string) predicate.DataSet { - return predicate.DataSet(sql.FieldContainsFold(FieldName, v)) -} - -// HasAssetPrice applies the HasEdge predicate on the "assetPrice" edge. -func HasAssetPrice() predicate.DataSet { - return predicate.DataSet(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, AssetPriceTable, AssetPricePrimaryKey...), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasAssetPriceWith applies the HasEdge predicate on the "assetPrice" edge with a given conditions (other predicates). -func HasAssetPriceWith(preds ...predicate.AssetPrice) predicate.DataSet { - return predicate.DataSet(func(s *sql.Selector) { - step := newAssetPriceStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.DataSet) predicate.DataSet { - return predicate.DataSet(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.DataSet) predicate.DataSet { - return predicate.DataSet(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.DataSet) predicate.DataSet { - return predicate.DataSet(sql.NotPredicates(p)) -} diff --git a/src/ent/dataset_create.go b/src/ent/dataset_create.go deleted file mode 100644 index 1786dc9d..00000000 --- a/src/ent/dataset_create.go +++ /dev/null @@ -1,491 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" -) - -// DataSetCreate is the builder for creating a DataSet entity. -type DataSetCreate struct { - config - mutation *DataSetMutation - hooks []Hook - conflict []sql.ConflictOption -} - -// SetName sets the "name" field. -func (dsc *DataSetCreate) SetName(s string) *DataSetCreate { - dsc.mutation.SetName(s) - return dsc -} - -// AddAssetPriceIDs adds the "assetPrice" edge to the AssetPrice entity by IDs. -func (dsc *DataSetCreate) AddAssetPriceIDs(ids ...int) *DataSetCreate { - dsc.mutation.AddAssetPriceIDs(ids...) - return dsc -} - -// AddAssetPrice adds the "assetPrice" edges to the AssetPrice entity. -func (dsc *DataSetCreate) AddAssetPrice(a ...*AssetPrice) *DataSetCreate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return dsc.AddAssetPriceIDs(ids...) -} - -// Mutation returns the DataSetMutation object of the builder. -func (dsc *DataSetCreate) Mutation() *DataSetMutation { - return dsc.mutation -} - -// Save creates the DataSet in the database. -func (dsc *DataSetCreate) Save(ctx context.Context) (*DataSet, error) { - return withHooks(ctx, dsc.sqlSave, dsc.mutation, dsc.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (dsc *DataSetCreate) SaveX(ctx context.Context) *DataSet { - v, err := dsc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (dsc *DataSetCreate) Exec(ctx context.Context) error { - _, err := dsc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dsc *DataSetCreate) ExecX(ctx context.Context) { - if err := dsc.Exec(ctx); err != nil { - panic(err) - } -} - -// check runs all checks and user-defined validators on the builder. -func (dsc *DataSetCreate) check() error { - if _, ok := dsc.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "DataSet.name"`)} - } - if v, ok := dsc.mutation.Name(); ok { - if err := dataset.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "DataSet.name": %w`, err)} - } - } - return nil -} - -func (dsc *DataSetCreate) sqlSave(ctx context.Context) (*DataSet, error) { - if err := dsc.check(); err != nil { - return nil, err - } - _node, _spec := dsc.createSpec() - if err := sqlgraph.CreateNode(ctx, dsc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - dsc.mutation.id = &_node.ID - dsc.mutation.done = true - return _node, nil -} - -func (dsc *DataSetCreate) createSpec() (*DataSet, *sqlgraph.CreateSpec) { - var ( - _node = &DataSet{config: dsc.config} - _spec = sqlgraph.NewCreateSpec(dataset.Table, sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt)) - ) - _spec.OnConflict = dsc.conflict - if value, ok := dsc.mutation.Name(); ok { - _spec.SetField(dataset.FieldName, field.TypeString, value) - _node.Name = value - } - if nodes := dsc.mutation.AssetPriceIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: dataset.AssetPriceTable, - Columns: dataset.AssetPricePrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(assetprice.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause -// of the `INSERT` statement. For example: -// -// client.DataSet.Create(). -// SetName(v). -// OnConflict( -// // Update the row with the new values -// // the was proposed for insertion. -// sql.ResolveWithNewValues(), -// ). -// // Override some of the fields with custom -// // update values. -// Update(func(u *ent.DataSetUpsert) { -// SetName(v+v). -// }). -// Exec(ctx) -func (dsc *DataSetCreate) OnConflict(opts ...sql.ConflictOption) *DataSetUpsertOne { - dsc.conflict = opts - return &DataSetUpsertOne{ - create: dsc, - } -} - -// OnConflictColumns calls `OnConflict` and configures the columns -// as conflict target. Using this option is equivalent to using: -// -// client.DataSet.Create(). -// OnConflict(sql.ConflictColumns(columns...)). -// Exec(ctx) -func (dsc *DataSetCreate) OnConflictColumns(columns ...string) *DataSetUpsertOne { - dsc.conflict = append(dsc.conflict, sql.ConflictColumns(columns...)) - return &DataSetUpsertOne{ - create: dsc, - } -} - -type ( - // DataSetUpsertOne is the builder for "upsert"-ing - // one DataSet node. - DataSetUpsertOne struct { - create *DataSetCreate - } - - // DataSetUpsert is the "OnConflict" setter. - DataSetUpsert struct { - *sql.UpdateSet - } -) - -// SetName sets the "name" field. -func (u *DataSetUpsert) SetName(v string) *DataSetUpsert { - u.Set(dataset.FieldName, v) - return u -} - -// UpdateName sets the "name" field to the value that was provided on create. -func (u *DataSetUpsert) UpdateName() *DataSetUpsert { - u.SetExcluded(dataset.FieldName) - return u -} - -// UpdateNewValues updates the mutable fields using the new values that were set on create. -// Using this option is equivalent to using: -// -// client.DataSet.Create(). -// OnConflict( -// sql.ResolveWithNewValues(), -// ). -// Exec(ctx) -func (u *DataSetUpsertOne) UpdateNewValues() *DataSetUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) - return u -} - -// Ignore sets each column to itself in case of conflict. -// Using this option is equivalent to using: -// -// client.DataSet.Create(). -// OnConflict(sql.ResolveWithIgnore()). -// Exec(ctx) -func (u *DataSetUpsertOne) Ignore() *DataSetUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) - return u -} - -// DoNothing configures the conflict_action to `DO NOTHING`. -// Supported only by SQLite and PostgreSQL. -func (u *DataSetUpsertOne) DoNothing() *DataSetUpsertOne { - u.create.conflict = append(u.create.conflict, sql.DoNothing()) - return u -} - -// Update allows overriding fields `UPDATE` values. See the DataSetCreate.OnConflict -// documentation for more info. -func (u *DataSetUpsertOne) Update(set func(*DataSetUpsert)) *DataSetUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { - set(&DataSetUpsert{UpdateSet: update}) - })) - return u -} - -// SetName sets the "name" field. -func (u *DataSetUpsertOne) SetName(v string) *DataSetUpsertOne { - return u.Update(func(s *DataSetUpsert) { - s.SetName(v) - }) -} - -// UpdateName sets the "name" field to the value that was provided on create. -func (u *DataSetUpsertOne) UpdateName() *DataSetUpsertOne { - return u.Update(func(s *DataSetUpsert) { - s.UpdateName() - }) -} - -// Exec executes the query. -func (u *DataSetUpsertOne) Exec(ctx context.Context) error { - if len(u.create.conflict) == 0 { - return errors.New("ent: missing options for DataSetCreate.OnConflict") - } - return u.create.Exec(ctx) -} - -// ExecX is like Exec, but panics if an error occurs. -func (u *DataSetUpsertOne) ExecX(ctx context.Context) { - if err := u.create.Exec(ctx); err != nil { - panic(err) - } -} - -// Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *DataSetUpsertOne) ID(ctx context.Context) (id int, err error) { - node, err := u.create.Save(ctx) - if err != nil { - return id, err - } - return node.ID, nil -} - -// IDX is like ID, but panics if an error occurs. -func (u *DataSetUpsertOne) IDX(ctx context.Context) int { - id, err := u.ID(ctx) - if err != nil { - panic(err) - } - return id -} - -// DataSetCreateBulk is the builder for creating many DataSet entities in bulk. -type DataSetCreateBulk struct { - config - err error - builders []*DataSetCreate - conflict []sql.ConflictOption -} - -// Save creates the DataSet entities in the database. -func (dscb *DataSetCreateBulk) Save(ctx context.Context) ([]*DataSet, error) { - if dscb.err != nil { - return nil, dscb.err - } - specs := make([]*sqlgraph.CreateSpec, len(dscb.builders)) - nodes := make([]*DataSet, len(dscb.builders)) - mutators := make([]Mutator, len(dscb.builders)) - for i := range dscb.builders { - func(i int, root context.Context) { - builder := dscb.builders[i] - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DataSetMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, dscb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - spec.OnConflict = dscb.conflict - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, dscb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, dscb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (dscb *DataSetCreateBulk) SaveX(ctx context.Context) []*DataSet { - v, err := dscb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (dscb *DataSetCreateBulk) Exec(ctx context.Context) error { - _, err := dscb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dscb *DataSetCreateBulk) ExecX(ctx context.Context) { - if err := dscb.Exec(ctx); err != nil { - panic(err) - } -} - -// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause -// of the `INSERT` statement. For example: -// -// client.DataSet.CreateBulk(builders...). -// OnConflict( -// // Update the row with the new values -// // the was proposed for insertion. -// sql.ResolveWithNewValues(), -// ). -// // Override some of the fields with custom -// // update values. -// Update(func(u *ent.DataSetUpsert) { -// SetName(v+v). -// }). -// Exec(ctx) -func (dscb *DataSetCreateBulk) OnConflict(opts ...sql.ConflictOption) *DataSetUpsertBulk { - dscb.conflict = opts - return &DataSetUpsertBulk{ - create: dscb, - } -} - -// OnConflictColumns calls `OnConflict` and configures the columns -// as conflict target. Using this option is equivalent to using: -// -// client.DataSet.Create(). -// OnConflict(sql.ConflictColumns(columns...)). -// Exec(ctx) -func (dscb *DataSetCreateBulk) OnConflictColumns(columns ...string) *DataSetUpsertBulk { - dscb.conflict = append(dscb.conflict, sql.ConflictColumns(columns...)) - return &DataSetUpsertBulk{ - create: dscb, - } -} - -// DataSetUpsertBulk is the builder for "upsert"-ing -// a bulk of DataSet nodes. -type DataSetUpsertBulk struct { - create *DataSetCreateBulk -} - -// UpdateNewValues updates the mutable fields using the new values that -// were set on create. Using this option is equivalent to using: -// -// client.DataSet.Create(). -// OnConflict( -// sql.ResolveWithNewValues(), -// ). -// Exec(ctx) -func (u *DataSetUpsertBulk) UpdateNewValues() *DataSetUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) - return u -} - -// Ignore sets each column to itself in case of conflict. -// Using this option is equivalent to using: -// -// client.DataSet.Create(). -// OnConflict(sql.ResolveWithIgnore()). -// Exec(ctx) -func (u *DataSetUpsertBulk) Ignore() *DataSetUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) - return u -} - -// DoNothing configures the conflict_action to `DO NOTHING`. -// Supported only by SQLite and PostgreSQL. -func (u *DataSetUpsertBulk) DoNothing() *DataSetUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.DoNothing()) - return u -} - -// Update allows overriding fields `UPDATE` values. See the DataSetCreateBulk.OnConflict -// documentation for more info. -func (u *DataSetUpsertBulk) Update(set func(*DataSetUpsert)) *DataSetUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { - set(&DataSetUpsert{UpdateSet: update}) - })) - return u -} - -// SetName sets the "name" field. -func (u *DataSetUpsertBulk) SetName(v string) *DataSetUpsertBulk { - return u.Update(func(s *DataSetUpsert) { - s.SetName(v) - }) -} - -// UpdateName sets the "name" field to the value that was provided on create. -func (u *DataSetUpsertBulk) UpdateName() *DataSetUpsertBulk { - return u.Update(func(s *DataSetUpsert) { - s.UpdateName() - }) -} - -// Exec executes the query. -func (u *DataSetUpsertBulk) Exec(ctx context.Context) error { - if u.create.err != nil { - return u.create.err - } - for i, b := range u.create.builders { - if len(b.conflict) != 0 { - return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the DataSetCreateBulk instead", i) - } - } - if len(u.create.conflict) == 0 { - return errors.New("ent: missing options for DataSetCreateBulk.OnConflict") - } - return u.create.Exec(ctx) -} - -// ExecX is like Exec, but panics if an error occurs. -func (u *DataSetUpsertBulk) ExecX(ctx context.Context) { - if err := u.create.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/src/ent/dataset_delete.go b/src/ent/dataset_delete.go deleted file mode 100644 index 2e004ff2..00000000 --- a/src/ent/dataset_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/KenshiTech/unchained/ent/dataset" - "github.com/KenshiTech/unchained/ent/predicate" -) - -// DataSetDelete is the builder for deleting a DataSet entity. -type DataSetDelete struct { - config - hooks []Hook - mutation *DataSetMutation -} - -// Where appends a list predicates to the DataSetDelete builder. -func (dsd *DataSetDelete) Where(ps ...predicate.DataSet) *DataSetDelete { - dsd.mutation.Where(ps...) - return dsd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (dsd *DataSetDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, dsd.sqlExec, dsd.mutation, dsd.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (dsd *DataSetDelete) ExecX(ctx context.Context) int { - n, err := dsd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (dsd *DataSetDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(dataset.Table, sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt)) - if ps := dsd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, dsd.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - dsd.mutation.done = true - return affected, err -} - -// DataSetDeleteOne is the builder for deleting a single DataSet entity. -type DataSetDeleteOne struct { - dsd *DataSetDelete -} - -// Where appends a list predicates to the DataSetDelete builder. -func (dsdo *DataSetDeleteOne) Where(ps ...predicate.DataSet) *DataSetDeleteOne { - dsdo.dsd.mutation.Where(ps...) - return dsdo -} - -// Exec executes the deletion query. -func (dsdo *DataSetDeleteOne) Exec(ctx context.Context) error { - n, err := dsdo.dsd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{dataset.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (dsdo *DataSetDeleteOne) ExecX(ctx context.Context) { - if err := dsdo.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/src/ent/dataset_query.go b/src/ent/dataset_query.go deleted file mode 100644 index 93bc4b64..00000000 --- a/src/ent/dataset_query.go +++ /dev/null @@ -1,636 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "database/sql/driver" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" - "github.com/KenshiTech/unchained/ent/predicate" -) - -// DataSetQuery is the builder for querying DataSet entities. -type DataSetQuery struct { - config - ctx *QueryContext - order []dataset.OrderOption - inters []Interceptor - predicates []predicate.DataSet - withAssetPrice *AssetPriceQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the DataSetQuery builder. -func (dsq *DataSetQuery) Where(ps ...predicate.DataSet) *DataSetQuery { - dsq.predicates = append(dsq.predicates, ps...) - return dsq -} - -// Limit the number of records to be returned by this query. -func (dsq *DataSetQuery) Limit(limit int) *DataSetQuery { - dsq.ctx.Limit = &limit - return dsq -} - -// Offset to start from. -func (dsq *DataSetQuery) Offset(offset int) *DataSetQuery { - dsq.ctx.Offset = &offset - return dsq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (dsq *DataSetQuery) Unique(unique bool) *DataSetQuery { - dsq.ctx.Unique = &unique - return dsq -} - -// Order specifies how the records should be ordered. -func (dsq *DataSetQuery) Order(o ...dataset.OrderOption) *DataSetQuery { - dsq.order = append(dsq.order, o...) - return dsq -} - -// QueryAssetPrice chains the current query on the "assetPrice" edge. -func (dsq *DataSetQuery) QueryAssetPrice() *AssetPriceQuery { - query := (&AssetPriceClient{config: dsq.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := dsq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := dsq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(dataset.Table, dataset.FieldID, selector), - sqlgraph.To(assetprice.Table, assetprice.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, dataset.AssetPriceTable, dataset.AssetPricePrimaryKey...), - ) - fromU = sqlgraph.SetNeighbors(dsq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first DataSet entity from the query. -// Returns a *NotFoundError when no DataSet was found. -func (dsq *DataSetQuery) First(ctx context.Context) (*DataSet, error) { - nodes, err := dsq.Limit(1).All(setContextOp(ctx, dsq.ctx, "First")) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{dataset.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (dsq *DataSetQuery) FirstX(ctx context.Context) *DataSet { - node, err := dsq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first DataSet ID from the query. -// Returns a *NotFoundError when no DataSet ID was found. -func (dsq *DataSetQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = dsq.Limit(1).IDs(setContextOp(ctx, dsq.ctx, "FirstID")); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{dataset.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (dsq *DataSetQuery) FirstIDX(ctx context.Context) int { - id, err := dsq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single DataSet entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one DataSet entity is found. -// Returns a *NotFoundError when no DataSet entities are found. -func (dsq *DataSetQuery) Only(ctx context.Context) (*DataSet, error) { - nodes, err := dsq.Limit(2).All(setContextOp(ctx, dsq.ctx, "Only")) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{dataset.Label} - default: - return nil, &NotSingularError{dataset.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (dsq *DataSetQuery) OnlyX(ctx context.Context) *DataSet { - node, err := dsq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only DataSet ID in the query. -// Returns a *NotSingularError when more than one DataSet ID is found. -// Returns a *NotFoundError when no entities are found. -func (dsq *DataSetQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = dsq.Limit(2).IDs(setContextOp(ctx, dsq.ctx, "OnlyID")); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{dataset.Label} - default: - err = &NotSingularError{dataset.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (dsq *DataSetQuery) OnlyIDX(ctx context.Context) int { - id, err := dsq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of DataSets. -func (dsq *DataSetQuery) All(ctx context.Context) ([]*DataSet, error) { - ctx = setContextOp(ctx, dsq.ctx, "All") - if err := dsq.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*DataSet, *DataSetQuery]() - return withInterceptors[[]*DataSet](ctx, dsq, qr, dsq.inters) -} - -// AllX is like All, but panics if an error occurs. -func (dsq *DataSetQuery) AllX(ctx context.Context) []*DataSet { - nodes, err := dsq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of DataSet IDs. -func (dsq *DataSetQuery) IDs(ctx context.Context) (ids []int, err error) { - if dsq.ctx.Unique == nil && dsq.path != nil { - dsq.Unique(true) - } - ctx = setContextOp(ctx, dsq.ctx, "IDs") - if err = dsq.Select(dataset.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (dsq *DataSetQuery) IDsX(ctx context.Context) []int { - ids, err := dsq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (dsq *DataSetQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, dsq.ctx, "Count") - if err := dsq.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, dsq, querierCount[*DataSetQuery](), dsq.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (dsq *DataSetQuery) CountX(ctx context.Context) int { - count, err := dsq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (dsq *DataSetQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, dsq.ctx, "Exist") - switch _, err := dsq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (dsq *DataSetQuery) ExistX(ctx context.Context) bool { - exist, err := dsq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the DataSetQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (dsq *DataSetQuery) Clone() *DataSetQuery { - if dsq == nil { - return nil - } - return &DataSetQuery{ - config: dsq.config, - ctx: dsq.ctx.Clone(), - order: append([]dataset.OrderOption{}, dsq.order...), - inters: append([]Interceptor{}, dsq.inters...), - predicates: append([]predicate.DataSet{}, dsq.predicates...), - withAssetPrice: dsq.withAssetPrice.Clone(), - // clone intermediate query. - sql: dsq.sql.Clone(), - path: dsq.path, - } -} - -// WithAssetPrice tells the query-builder to eager-load the nodes that are connected to -// the "assetPrice" edge. The optional arguments are used to configure the query builder of the edge. -func (dsq *DataSetQuery) WithAssetPrice(opts ...func(*AssetPriceQuery)) *DataSetQuery { - query := (&AssetPriceClient{config: dsq.config}).Query() - for _, opt := range opts { - opt(query) - } - dsq.withAssetPrice = query - return dsq -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.DataSet.Query(). -// GroupBy(dataset.FieldName). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (dsq *DataSetQuery) GroupBy(field string, fields ...string) *DataSetGroupBy { - dsq.ctx.Fields = append([]string{field}, fields...) - grbuild := &DataSetGroupBy{build: dsq} - grbuild.flds = &dsq.ctx.Fields - grbuild.label = dataset.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// } -// -// client.DataSet.Query(). -// Select(dataset.FieldName). -// Scan(ctx, &v) -func (dsq *DataSetQuery) Select(fields ...string) *DataSetSelect { - dsq.ctx.Fields = append(dsq.ctx.Fields, fields...) - sbuild := &DataSetSelect{DataSetQuery: dsq} - sbuild.label = dataset.Label - sbuild.flds, sbuild.scan = &dsq.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a DataSetSelect configured with the given aggregations. -func (dsq *DataSetQuery) Aggregate(fns ...AggregateFunc) *DataSetSelect { - return dsq.Select().Aggregate(fns...) -} - -func (dsq *DataSetQuery) prepareQuery(ctx context.Context) error { - for _, inter := range dsq.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, dsq); err != nil { - return err - } - } - } - for _, f := range dsq.ctx.Fields { - if !dataset.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if dsq.path != nil { - prev, err := dsq.path(ctx) - if err != nil { - return err - } - dsq.sql = prev - } - return nil -} - -func (dsq *DataSetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*DataSet, error) { - var ( - nodes = []*DataSet{} - _spec = dsq.querySpec() - loadedTypes = [1]bool{ - dsq.withAssetPrice != nil, - } - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*DataSet).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &DataSet{config: dsq.config} - nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, dsq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - if query := dsq.withAssetPrice; query != nil { - if err := dsq.loadAssetPrice(ctx, query, nodes, - func(n *DataSet) { n.Edges.AssetPrice = []*AssetPrice{} }, - func(n *DataSet, e *AssetPrice) { n.Edges.AssetPrice = append(n.Edges.AssetPrice, e) }); err != nil { - return nil, err - } - } - return nodes, nil -} - -func (dsq *DataSetQuery) loadAssetPrice(ctx context.Context, query *AssetPriceQuery, nodes []*DataSet, init func(*DataSet), assign func(*DataSet, *AssetPrice)) error { - edgeIDs := make([]driver.Value, len(nodes)) - byID := make(map[int]*DataSet) - nids := make(map[int]map[*DataSet]struct{}) - for i, node := range nodes { - edgeIDs[i] = node.ID - byID[node.ID] = node - if init != nil { - init(node) - } - } - query.Where(func(s *sql.Selector) { - joinT := sql.Table(dataset.AssetPriceTable) - s.Join(joinT).On(s.C(assetprice.FieldID), joinT.C(dataset.AssetPricePrimaryKey[0])) - s.Where(sql.InValues(joinT.C(dataset.AssetPricePrimaryKey[1]), edgeIDs...)) - columns := s.SelectedColumns() - s.Select(joinT.C(dataset.AssetPricePrimaryKey[1])) - s.AppendSelect(columns...) - s.SetDistinct(false) - }) - if err := query.prepareQuery(ctx); err != nil { - return err - } - qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { - assign := spec.Assign - values := spec.ScanValues - spec.ScanValues = func(columns []string) ([]any, error) { - values, err := values(columns[1:]) - if err != nil { - return nil, err - } - return append([]any{new(sql.NullInt64)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := int(values[0].(*sql.NullInt64).Int64) - inValue := int(values[1].(*sql.NullInt64).Int64) - if nids[inValue] == nil { - nids[inValue] = map[*DataSet]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) - } - nids[inValue][byID[outValue]] = struct{}{} - return nil - } - }) - }) - neighbors, err := withInterceptors[[]*AssetPrice](ctx, query, qr, query.inters) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nids[n.ID] - if !ok { - return fmt.Errorf(`unexpected "assetPrice" node returned %v`, n.ID) - } - for kn := range nodes { - assign(kn, n) - } - } - return nil -} - -func (dsq *DataSetQuery) sqlCount(ctx context.Context) (int, error) { - _spec := dsq.querySpec() - _spec.Node.Columns = dsq.ctx.Fields - if len(dsq.ctx.Fields) > 0 { - _spec.Unique = dsq.ctx.Unique != nil && *dsq.ctx.Unique - } - return sqlgraph.CountNodes(ctx, dsq.driver, _spec) -} - -func (dsq *DataSetQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(dataset.Table, dataset.Columns, sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt)) - _spec.From = dsq.sql - if unique := dsq.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if dsq.path != nil { - _spec.Unique = true - } - if fields := dsq.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, dataset.FieldID) - for i := range fields { - if fields[i] != dataset.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := dsq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := dsq.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := dsq.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := dsq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (dsq *DataSetQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(dsq.driver.Dialect()) - t1 := builder.Table(dataset.Table) - columns := dsq.ctx.Fields - if len(columns) == 0 { - columns = dataset.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if dsq.sql != nil { - selector = dsq.sql - selector.Select(selector.Columns(columns...)...) - } - if dsq.ctx.Unique != nil && *dsq.ctx.Unique { - selector.Distinct() - } - for _, p := range dsq.predicates { - p(selector) - } - for _, p := range dsq.order { - p(selector) - } - if offset := dsq.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := dsq.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// DataSetGroupBy is the group-by builder for DataSet entities. -type DataSetGroupBy struct { - selector - build *DataSetQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (dsgb *DataSetGroupBy) Aggregate(fns ...AggregateFunc) *DataSetGroupBy { - dsgb.fns = append(dsgb.fns, fns...) - return dsgb -} - -// Scan applies the selector query and scans the result into the given value. -func (dsgb *DataSetGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, dsgb.build.ctx, "GroupBy") - if err := dsgb.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*DataSetQuery, *DataSetGroupBy](ctx, dsgb.build, dsgb, dsgb.build.inters, v) -} - -func (dsgb *DataSetGroupBy) sqlScan(ctx context.Context, root *DataSetQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(dsgb.fns)) - for _, fn := range dsgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*dsgb.flds)+len(dsgb.fns)) - for _, f := range *dsgb.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*dsgb.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := dsgb.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// DataSetSelect is the builder for selecting fields of DataSet entities. -type DataSetSelect struct { - *DataSetQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (dss *DataSetSelect) Aggregate(fns ...AggregateFunc) *DataSetSelect { - dss.fns = append(dss.fns, fns...) - return dss -} - -// Scan applies the selector query and scans the result into the given value. -func (dss *DataSetSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, dss.ctx, "Select") - if err := dss.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*DataSetQuery, *DataSetSelect](ctx, dss.DataSetQuery, dss, dss.inters, v) -} - -func (dss *DataSetSelect) sqlScan(ctx context.Context, root *DataSetQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(dss.fns)) - for _, fn := range dss.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*dss.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := dss.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/src/ent/dataset_update.go b/src/ent/dataset_update.go deleted file mode 100644 index 9d9ac79c..00000000 --- a/src/ent/dataset_update.go +++ /dev/null @@ -1,398 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" - "github.com/KenshiTech/unchained/ent/predicate" -) - -// DataSetUpdate is the builder for updating DataSet entities. -type DataSetUpdate struct { - config - hooks []Hook - mutation *DataSetMutation -} - -// Where appends a list predicates to the DataSetUpdate builder. -func (dsu *DataSetUpdate) Where(ps ...predicate.DataSet) *DataSetUpdate { - dsu.mutation.Where(ps...) - return dsu -} - -// SetName sets the "name" field. -func (dsu *DataSetUpdate) SetName(s string) *DataSetUpdate { - dsu.mutation.SetName(s) - return dsu -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (dsu *DataSetUpdate) SetNillableName(s *string) *DataSetUpdate { - if s != nil { - dsu.SetName(*s) - } - return dsu -} - -// AddAssetPriceIDs adds the "assetPrice" edge to the AssetPrice entity by IDs. -func (dsu *DataSetUpdate) AddAssetPriceIDs(ids ...int) *DataSetUpdate { - dsu.mutation.AddAssetPriceIDs(ids...) - return dsu -} - -// AddAssetPrice adds the "assetPrice" edges to the AssetPrice entity. -func (dsu *DataSetUpdate) AddAssetPrice(a ...*AssetPrice) *DataSetUpdate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return dsu.AddAssetPriceIDs(ids...) -} - -// Mutation returns the DataSetMutation object of the builder. -func (dsu *DataSetUpdate) Mutation() *DataSetMutation { - return dsu.mutation -} - -// ClearAssetPrice clears all "assetPrice" edges to the AssetPrice entity. -func (dsu *DataSetUpdate) ClearAssetPrice() *DataSetUpdate { - dsu.mutation.ClearAssetPrice() - return dsu -} - -// RemoveAssetPriceIDs removes the "assetPrice" edge to AssetPrice entities by IDs. -func (dsu *DataSetUpdate) RemoveAssetPriceIDs(ids ...int) *DataSetUpdate { - dsu.mutation.RemoveAssetPriceIDs(ids...) - return dsu -} - -// RemoveAssetPrice removes "assetPrice" edges to AssetPrice entities. -func (dsu *DataSetUpdate) RemoveAssetPrice(a ...*AssetPrice) *DataSetUpdate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return dsu.RemoveAssetPriceIDs(ids...) -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (dsu *DataSetUpdate) Save(ctx context.Context) (int, error) { - return withHooks(ctx, dsu.sqlSave, dsu.mutation, dsu.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (dsu *DataSetUpdate) SaveX(ctx context.Context) int { - affected, err := dsu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (dsu *DataSetUpdate) Exec(ctx context.Context) error { - _, err := dsu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dsu *DataSetUpdate) ExecX(ctx context.Context) { - if err := dsu.Exec(ctx); err != nil { - panic(err) - } -} - -// check runs all checks and user-defined validators on the builder. -func (dsu *DataSetUpdate) check() error { - if v, ok := dsu.mutation.Name(); ok { - if err := dataset.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "DataSet.name": %w`, err)} - } - } - return nil -} - -func (dsu *DataSetUpdate) sqlSave(ctx context.Context) (n int, err error) { - if err := dsu.check(); err != nil { - return n, err - } - _spec := sqlgraph.NewUpdateSpec(dataset.Table, dataset.Columns, sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt)) - if ps := dsu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := dsu.mutation.Name(); ok { - _spec.SetField(dataset.FieldName, field.TypeString, value) - } - if dsu.mutation.AssetPriceCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: dataset.AssetPriceTable, - Columns: dataset.AssetPricePrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(assetprice.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := dsu.mutation.RemovedAssetPriceIDs(); len(nodes) > 0 && !dsu.mutation.AssetPriceCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: dataset.AssetPriceTable, - Columns: dataset.AssetPricePrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(assetprice.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := dsu.mutation.AssetPriceIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: dataset.AssetPriceTable, - Columns: dataset.AssetPricePrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(assetprice.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if n, err = sqlgraph.UpdateNodes(ctx, dsu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{dataset.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - dsu.mutation.done = true - return n, nil -} - -// DataSetUpdateOne is the builder for updating a single DataSet entity. -type DataSetUpdateOne struct { - config - fields []string - hooks []Hook - mutation *DataSetMutation -} - -// SetName sets the "name" field. -func (dsuo *DataSetUpdateOne) SetName(s string) *DataSetUpdateOne { - dsuo.mutation.SetName(s) - return dsuo -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (dsuo *DataSetUpdateOne) SetNillableName(s *string) *DataSetUpdateOne { - if s != nil { - dsuo.SetName(*s) - } - return dsuo -} - -// AddAssetPriceIDs adds the "assetPrice" edge to the AssetPrice entity by IDs. -func (dsuo *DataSetUpdateOne) AddAssetPriceIDs(ids ...int) *DataSetUpdateOne { - dsuo.mutation.AddAssetPriceIDs(ids...) - return dsuo -} - -// AddAssetPrice adds the "assetPrice" edges to the AssetPrice entity. -func (dsuo *DataSetUpdateOne) AddAssetPrice(a ...*AssetPrice) *DataSetUpdateOne { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return dsuo.AddAssetPriceIDs(ids...) -} - -// Mutation returns the DataSetMutation object of the builder. -func (dsuo *DataSetUpdateOne) Mutation() *DataSetMutation { - return dsuo.mutation -} - -// ClearAssetPrice clears all "assetPrice" edges to the AssetPrice entity. -func (dsuo *DataSetUpdateOne) ClearAssetPrice() *DataSetUpdateOne { - dsuo.mutation.ClearAssetPrice() - return dsuo -} - -// RemoveAssetPriceIDs removes the "assetPrice" edge to AssetPrice entities by IDs. -func (dsuo *DataSetUpdateOne) RemoveAssetPriceIDs(ids ...int) *DataSetUpdateOne { - dsuo.mutation.RemoveAssetPriceIDs(ids...) - return dsuo -} - -// RemoveAssetPrice removes "assetPrice" edges to AssetPrice entities. -func (dsuo *DataSetUpdateOne) RemoveAssetPrice(a ...*AssetPrice) *DataSetUpdateOne { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID - } - return dsuo.RemoveAssetPriceIDs(ids...) -} - -// Where appends a list predicates to the DataSetUpdate builder. -func (dsuo *DataSetUpdateOne) Where(ps ...predicate.DataSet) *DataSetUpdateOne { - dsuo.mutation.Where(ps...) - return dsuo -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (dsuo *DataSetUpdateOne) Select(field string, fields ...string) *DataSetUpdateOne { - dsuo.fields = append([]string{field}, fields...) - return dsuo -} - -// Save executes the query and returns the updated DataSet entity. -func (dsuo *DataSetUpdateOne) Save(ctx context.Context) (*DataSet, error) { - return withHooks(ctx, dsuo.sqlSave, dsuo.mutation, dsuo.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (dsuo *DataSetUpdateOne) SaveX(ctx context.Context) *DataSet { - node, err := dsuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (dsuo *DataSetUpdateOne) Exec(ctx context.Context) error { - _, err := dsuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dsuo *DataSetUpdateOne) ExecX(ctx context.Context) { - if err := dsuo.Exec(ctx); err != nil { - panic(err) - } -} - -// check runs all checks and user-defined validators on the builder. -func (dsuo *DataSetUpdateOne) check() error { - if v, ok := dsuo.mutation.Name(); ok { - if err := dataset.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "DataSet.name": %w`, err)} - } - } - return nil -} - -func (dsuo *DataSetUpdateOne) sqlSave(ctx context.Context) (_node *DataSet, err error) { - if err := dsuo.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(dataset.Table, dataset.Columns, sqlgraph.NewFieldSpec(dataset.FieldID, field.TypeInt)) - id, ok := dsuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DataSet.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := dsuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, dataset.FieldID) - for _, f := range fields { - if !dataset.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != dataset.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := dsuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := dsuo.mutation.Name(); ok { - _spec.SetField(dataset.FieldName, field.TypeString, value) - } - if dsuo.mutation.AssetPriceCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: dataset.AssetPriceTable, - Columns: dataset.AssetPricePrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(assetprice.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := dsuo.mutation.RemovedAssetPriceIDs(); len(nodes) > 0 && !dsuo.mutation.AssetPriceCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: dataset.AssetPriceTable, - Columns: dataset.AssetPricePrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(assetprice.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := dsuo.mutation.AssetPriceIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: dataset.AssetPriceTable, - Columns: dataset.AssetPricePrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(assetprice.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &DataSet{config: dsuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, dsuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{dataset.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - dsuo.mutation.done = true - return _node, nil -} diff --git a/src/ent/ent.go b/src/ent/ent.go index 0e998020..3bd1f0b6 100644 --- a/src/ent/ent.go +++ b/src/ent/ent.go @@ -13,7 +13,6 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" "github.com/KenshiTech/unchained/ent/signer" ) @@ -76,7 +75,6 @@ func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ assetprice.Table: assetprice.ValidColumn, - dataset.Table: dataset.ValidColumn, signer.Table: signer.ValidColumn, }) }) diff --git a/src/ent/hook/hook.go b/src/ent/hook/hook.go index c7c52228..7a430193 100644 --- a/src/ent/hook/hook.go +++ b/src/ent/hook/hook.go @@ -21,18 +21,6 @@ func (f AssetPriceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AssetPriceMutation", m) } -// The DataSetFunc type is an adapter to allow the use of ordinary -// function as DataSet mutator. -type DataSetFunc func(context.Context, *ent.DataSetMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f DataSetFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.DataSetMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DataSetMutation", m) -} - // The SignerFunc type is an adapter to allow the use of ordinary // function as Signer mutator. type SignerFunc func(context.Context, *ent.SignerMutation) (ent.Value, error) diff --git a/src/ent/migrate/schema.go b/src/ent/migrate/schema.go index 9f23e14e..d61fbf45 100644 --- a/src/ent/migrate/schema.go +++ b/src/ent/migrate/schema.go @@ -11,10 +11,13 @@ var ( // AssetPricesColumns holds the columns for the "asset_prices" table. AssetPricesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "block", Type: field.TypeUint64, Unique: true}, + {Name: "block", Type: field.TypeUint64}, {Name: "signers_count", Type: field.TypeUint64, Nullable: true}, {Name: "price", Type: field.TypeString}, {Name: "signature", Type: field.TypeBytes, Size: 96}, + {Name: "asset", Type: field.TypeString, Nullable: true}, + {Name: "chain", Type: field.TypeString, Nullable: true}, + {Name: "pair", Type: field.TypeString, Nullable: true}, } // AssetPricesTable holds the schema information for the "asset_prices" table. AssetPricesTable = &schema.Table{ @@ -23,27 +26,9 @@ var ( PrimaryKey: []*schema.Column{AssetPricesColumns[0]}, Indexes: []*schema.Index{ { - Name: "assetprice_block", + Name: "assetprice_block_chain_asset_pair", Unique: true, - Columns: []*schema.Column{AssetPricesColumns[1]}, - }, - }, - } - // DataSetsColumns holds the columns for the "data_sets" table. - DataSetsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "name", Type: field.TypeString, Unique: true}, - } - // DataSetsTable holds the schema information for the "data_sets" table. - DataSetsTable = &schema.Table{ - Name: "data_sets", - Columns: DataSetsColumns, - PrimaryKey: []*schema.Column{DataSetsColumns[0]}, - Indexes: []*schema.Index{ - { - Name: "dataset_name", - Unique: true, - Columns: []*schema.Column{DataSetsColumns[1]}, + Columns: []*schema.Column{AssetPricesColumns[1], AssetPricesColumns[6], AssetPricesColumns[5], AssetPricesColumns[7]}, }, }, } @@ -73,31 +58,6 @@ var ( }, }, } - // AssetPriceDataSetColumns holds the columns for the "asset_price_dataSet" table. - AssetPriceDataSetColumns = []*schema.Column{ - {Name: "asset_price_id", Type: field.TypeInt}, - {Name: "data_set_id", Type: field.TypeInt}, - } - // AssetPriceDataSetTable holds the schema information for the "asset_price_dataSet" table. - AssetPriceDataSetTable = &schema.Table{ - Name: "asset_price_dataSet", - Columns: AssetPriceDataSetColumns, - PrimaryKey: []*schema.Column{AssetPriceDataSetColumns[0], AssetPriceDataSetColumns[1]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "asset_price_dataSet_asset_price_id", - Columns: []*schema.Column{AssetPriceDataSetColumns[0]}, - RefColumns: []*schema.Column{AssetPricesColumns[0]}, - OnDelete: schema.Cascade, - }, - { - Symbol: "asset_price_dataSet_data_set_id", - Columns: []*schema.Column{AssetPriceDataSetColumns[1]}, - RefColumns: []*schema.Column{DataSetsColumns[0]}, - OnDelete: schema.Cascade, - }, - }, - } // AssetPriceSignersColumns holds the columns for the "asset_price_signers" table. AssetPriceSignersColumns = []*schema.Column{ {Name: "asset_price_id", Type: field.TypeInt}, @@ -126,16 +86,12 @@ var ( // Tables holds all the tables in the schema. Tables = []*schema.Table{ AssetPricesTable, - DataSetsTable, SignersTable, - AssetPriceDataSetTable, AssetPriceSignersTable, } ) func init() { - AssetPriceDataSetTable.ForeignKeys[0].RefTable = AssetPricesTable - AssetPriceDataSetTable.ForeignKeys[1].RefTable = DataSetsTable AssetPriceSignersTable.ForeignKeys[0].RefTable = AssetPricesTable AssetPriceSignersTable.ForeignKeys[1].RefTable = SignersTable } diff --git a/src/ent/mutation.go b/src/ent/mutation.go index d35e1951..bc23034e 100644 --- a/src/ent/mutation.go +++ b/src/ent/mutation.go @@ -12,7 +12,6 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" "github.com/KenshiTech/unchained/ent/predicate" "github.com/KenshiTech/unchained/ent/signer" ) @@ -27,7 +26,6 @@ const ( // Node types. TypeAssetPrice = "AssetPrice" - TypeDataSet = "DataSet" TypeSigner = "Signer" ) @@ -43,10 +41,10 @@ type AssetPriceMutation struct { addsignersCount *int64 price **big.Int signature *[]byte + asset *string + chain *string + pair *string clearedFields map[string]struct{} - dataSet map[int]struct{} - removeddataSet map[int]struct{} - cleareddataSet bool signers map[int]struct{} removedsigners map[int]struct{} clearedsigners bool @@ -351,58 +349,151 @@ func (m *AssetPriceMutation) ResetSignature() { m.signature = nil } -// AddDataSetIDs adds the "dataSet" edge to the DataSet entity by ids. -func (m *AssetPriceMutation) AddDataSetIDs(ids ...int) { - if m.dataSet == nil { - m.dataSet = make(map[int]struct{}) +// SetAsset sets the "asset" field. +func (m *AssetPriceMutation) SetAsset(s string) { + m.asset = &s +} + +// Asset returns the value of the "asset" field in the mutation. +func (m *AssetPriceMutation) Asset() (r string, exists bool) { + v := m.asset + if v == nil { + return } - for i := range ids { - m.dataSet[ids[i]] = struct{}{} + return *v, true +} + +// OldAsset returns the old "asset" field's value of the AssetPrice entity. +// If the AssetPrice object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AssetPriceMutation) OldAsset(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAsset is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAsset requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAsset: %w", err) } + return oldValue.Asset, nil +} + +// ClearAsset clears the value of the "asset" field. +func (m *AssetPriceMutation) ClearAsset() { + m.asset = nil + m.clearedFields[assetprice.FieldAsset] = struct{}{} +} + +// AssetCleared returns if the "asset" field was cleared in this mutation. +func (m *AssetPriceMutation) AssetCleared() bool { + _, ok := m.clearedFields[assetprice.FieldAsset] + return ok } -// ClearDataSet clears the "dataSet" edge to the DataSet entity. -func (m *AssetPriceMutation) ClearDataSet() { - m.cleareddataSet = true +// ResetAsset resets all changes to the "asset" field. +func (m *AssetPriceMutation) ResetAsset() { + m.asset = nil + delete(m.clearedFields, assetprice.FieldAsset) } -// DataSetCleared reports if the "dataSet" edge to the DataSet entity was cleared. -func (m *AssetPriceMutation) DataSetCleared() bool { - return m.cleareddataSet +// SetChain sets the "chain" field. +func (m *AssetPriceMutation) SetChain(s string) { + m.chain = &s } -// RemoveDataSetIDs removes the "dataSet" edge to the DataSet entity by IDs. -func (m *AssetPriceMutation) RemoveDataSetIDs(ids ...int) { - if m.removeddataSet == nil { - m.removeddataSet = make(map[int]struct{}) +// Chain returns the value of the "chain" field in the mutation. +func (m *AssetPriceMutation) Chain() (r string, exists bool) { + v := m.chain + if v == nil { + return } - for i := range ids { - delete(m.dataSet, ids[i]) - m.removeddataSet[ids[i]] = struct{}{} + return *v, true +} + +// OldChain returns the old "chain" field's value of the AssetPrice entity. +// If the AssetPrice object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AssetPriceMutation) OldChain(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChain is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChain requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChain: %w", err) } + return oldValue.Chain, nil } -// RemovedDataSet returns the removed IDs of the "dataSet" edge to the DataSet entity. -func (m *AssetPriceMutation) RemovedDataSetIDs() (ids []int) { - for id := range m.removeddataSet { - ids = append(ids, id) +// ClearChain clears the value of the "chain" field. +func (m *AssetPriceMutation) ClearChain() { + m.chain = nil + m.clearedFields[assetprice.FieldChain] = struct{}{} +} + +// ChainCleared returns if the "chain" field was cleared in this mutation. +func (m *AssetPriceMutation) ChainCleared() bool { + _, ok := m.clearedFields[assetprice.FieldChain] + return ok +} + +// ResetChain resets all changes to the "chain" field. +func (m *AssetPriceMutation) ResetChain() { + m.chain = nil + delete(m.clearedFields, assetprice.FieldChain) +} + +// SetPair sets the "pair" field. +func (m *AssetPriceMutation) SetPair(s string) { + m.pair = &s +} + +// Pair returns the value of the "pair" field in the mutation. +func (m *AssetPriceMutation) Pair() (r string, exists bool) { + v := m.pair + if v == nil { + return } - return + return *v, true } -// DataSetIDs returns the "dataSet" edge IDs in the mutation. -func (m *AssetPriceMutation) DataSetIDs() (ids []int) { - for id := range m.dataSet { - ids = append(ids, id) +// OldPair returns the old "pair" field's value of the AssetPrice entity. +// If the AssetPrice object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AssetPriceMutation) OldPair(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPair is only allowed on UpdateOne operations") } - return + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPair requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPair: %w", err) + } + return oldValue.Pair, nil +} + +// ClearPair clears the value of the "pair" field. +func (m *AssetPriceMutation) ClearPair() { + m.pair = nil + m.clearedFields[assetprice.FieldPair] = struct{}{} +} + +// PairCleared returns if the "pair" field was cleared in this mutation. +func (m *AssetPriceMutation) PairCleared() bool { + _, ok := m.clearedFields[assetprice.FieldPair] + return ok } -// ResetDataSet resets all changes to the "dataSet" edge. -func (m *AssetPriceMutation) ResetDataSet() { - m.dataSet = nil - m.cleareddataSet = false - m.removeddataSet = nil +// ResetPair resets all changes to the "pair" field. +func (m *AssetPriceMutation) ResetPair() { + m.pair = nil + delete(m.clearedFields, assetprice.FieldPair) } // AddSignerIDs adds the "signers" edge to the Signer entity by ids. @@ -493,7 +584,7 @@ func (m *AssetPriceMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *AssetPriceMutation) Fields() []string { - fields := make([]string, 0, 4) + fields := make([]string, 0, 7) if m.block != nil { fields = append(fields, assetprice.FieldBlock) } @@ -506,6 +597,15 @@ func (m *AssetPriceMutation) Fields() []string { if m.signature != nil { fields = append(fields, assetprice.FieldSignature) } + if m.asset != nil { + fields = append(fields, assetprice.FieldAsset) + } + if m.chain != nil { + fields = append(fields, assetprice.FieldChain) + } + if m.pair != nil { + fields = append(fields, assetprice.FieldPair) + } return fields } @@ -522,6 +622,12 @@ func (m *AssetPriceMutation) Field(name string) (ent.Value, bool) { return m.Price() case assetprice.FieldSignature: return m.Signature() + case assetprice.FieldAsset: + return m.Asset() + case assetprice.FieldChain: + return m.Chain() + case assetprice.FieldPair: + return m.Pair() } return nil, false } @@ -539,6 +645,12 @@ func (m *AssetPriceMutation) OldField(ctx context.Context, name string) (ent.Val return m.OldPrice(ctx) case assetprice.FieldSignature: return m.OldSignature(ctx) + case assetprice.FieldAsset: + return m.OldAsset(ctx) + case assetprice.FieldChain: + return m.OldChain(ctx) + case assetprice.FieldPair: + return m.OldPair(ctx) } return nil, fmt.Errorf("unknown AssetPrice field %s", name) } @@ -576,6 +688,27 @@ func (m *AssetPriceMutation) SetField(name string, value ent.Value) error { } m.SetSignature(v) return nil + case assetprice.FieldAsset: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAsset(v) + return nil + case assetprice.FieldChain: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChain(v) + return nil + case assetprice.FieldPair: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPair(v) + return nil } return fmt.Errorf("unknown AssetPrice field %s", name) } @@ -636,6 +769,15 @@ func (m *AssetPriceMutation) ClearedFields() []string { if m.FieldCleared(assetprice.FieldSignersCount) { fields = append(fields, assetprice.FieldSignersCount) } + if m.FieldCleared(assetprice.FieldAsset) { + fields = append(fields, assetprice.FieldAsset) + } + if m.FieldCleared(assetprice.FieldChain) { + fields = append(fields, assetprice.FieldChain) + } + if m.FieldCleared(assetprice.FieldPair) { + fields = append(fields, assetprice.FieldPair) + } return fields } @@ -653,6 +795,15 @@ func (m *AssetPriceMutation) ClearField(name string) error { case assetprice.FieldSignersCount: m.ClearSignersCount() return nil + case assetprice.FieldAsset: + m.ClearAsset() + return nil + case assetprice.FieldChain: + m.ClearChain() + return nil + case assetprice.FieldPair: + m.ClearPair() + return nil } return fmt.Errorf("unknown AssetPrice nullable field %s", name) } @@ -673,16 +824,22 @@ func (m *AssetPriceMutation) ResetField(name string) error { case assetprice.FieldSignature: m.ResetSignature() return nil + case assetprice.FieldAsset: + m.ResetAsset() + return nil + case assetprice.FieldChain: + m.ResetChain() + return nil + case assetprice.FieldPair: + m.ResetPair() + return nil } return fmt.Errorf("unknown AssetPrice field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AssetPriceMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.dataSet != nil { - edges = append(edges, assetprice.EdgeDataSet) - } + edges := make([]string, 0, 1) if m.signers != nil { edges = append(edges, assetprice.EdgeSigners) } @@ -693,12 +850,6 @@ func (m *AssetPriceMutation) AddedEdges() []string { // name in this mutation. func (m *AssetPriceMutation) AddedIDs(name string) []ent.Value { switch name { - case assetprice.EdgeDataSet: - ids := make([]ent.Value, 0, len(m.dataSet)) - for id := range m.dataSet { - ids = append(ids, id) - } - return ids case assetprice.EdgeSigners: ids := make([]ent.Value, 0, len(m.signers)) for id := range m.signers { @@ -711,10 +862,7 @@ func (m *AssetPriceMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *AssetPriceMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) - if m.removeddataSet != nil { - edges = append(edges, assetprice.EdgeDataSet) - } + edges := make([]string, 0, 1) if m.removedsigners != nil { edges = append(edges, assetprice.EdgeSigners) } @@ -725,12 +873,6 @@ func (m *AssetPriceMutation) RemovedEdges() []string { // the given name in this mutation. func (m *AssetPriceMutation) RemovedIDs(name string) []ent.Value { switch name { - case assetprice.EdgeDataSet: - ids := make([]ent.Value, 0, len(m.removeddataSet)) - for id := range m.removeddataSet { - ids = append(ids, id) - } - return ids case assetprice.EdgeSigners: ids := make([]ent.Value, 0, len(m.removedsigners)) for id := range m.removedsigners { @@ -743,10 +885,7 @@ func (m *AssetPriceMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AssetPriceMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.cleareddataSet { - edges = append(edges, assetprice.EdgeDataSet) - } + edges := make([]string, 0, 1) if m.clearedsigners { edges = append(edges, assetprice.EdgeSigners) } @@ -757,8 +896,6 @@ func (m *AssetPriceMutation) ClearedEdges() []string { // was cleared in this mutation. func (m *AssetPriceMutation) EdgeCleared(name string) bool { switch name { - case assetprice.EdgeDataSet: - return m.cleareddataSet case assetprice.EdgeSigners: return m.clearedsigners } @@ -777,9 +914,6 @@ func (m *AssetPriceMutation) ClearEdge(name string) error { // It returns an error if the edge is not defined in the schema. func (m *AssetPriceMutation) ResetEdge(name string) error { switch name { - case assetprice.EdgeDataSet: - m.ResetDataSet() - return nil case assetprice.EdgeSigners: m.ResetSigners() return nil @@ -787,425 +921,6 @@ func (m *AssetPriceMutation) ResetEdge(name string) error { return fmt.Errorf("unknown AssetPrice edge %s", name) } -// DataSetMutation represents an operation that mutates the DataSet nodes in the graph. -type DataSetMutation struct { - config - op Op - typ string - id *int - name *string - clearedFields map[string]struct{} - assetPrice map[int]struct{} - removedassetPrice map[int]struct{} - clearedassetPrice bool - done bool - oldValue func(context.Context) (*DataSet, error) - predicates []predicate.DataSet -} - -var _ ent.Mutation = (*DataSetMutation)(nil) - -// datasetOption allows management of the mutation configuration using functional options. -type datasetOption func(*DataSetMutation) - -// newDataSetMutation creates new mutation for the DataSet entity. -func newDataSetMutation(c config, op Op, opts ...datasetOption) *DataSetMutation { - m := &DataSetMutation{ - config: c, - op: op, - typ: TypeDataSet, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withDataSetID sets the ID field of the mutation. -func withDataSetID(id int) datasetOption { - return func(m *DataSetMutation) { - var ( - err error - once sync.Once - value *DataSet - ) - m.oldValue = func(ctx context.Context) (*DataSet, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().DataSet.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withDataSet sets the old DataSet of the mutation. -func withDataSet(node *DataSet) datasetOption { - return func(m *DataSetMutation) { - m.oldValue = func(context.Context) (*DataSet, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m DataSetMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m DataSetMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *DataSetMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *DataSetMutation) IDs(ctx context.Context) ([]int, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []int{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().DataSet.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetName sets the "name" field. -func (m *DataSetMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *DataSetMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "name" field's value of the DataSet entity. -// If the DataSet object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *DataSetMutation) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldName is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldName requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *DataSetMutation) ResetName() { - m.name = nil -} - -// AddAssetPriceIDs adds the "assetPrice" edge to the AssetPrice entity by ids. -func (m *DataSetMutation) AddAssetPriceIDs(ids ...int) { - if m.assetPrice == nil { - m.assetPrice = make(map[int]struct{}) - } - for i := range ids { - m.assetPrice[ids[i]] = struct{}{} - } -} - -// ClearAssetPrice clears the "assetPrice" edge to the AssetPrice entity. -func (m *DataSetMutation) ClearAssetPrice() { - m.clearedassetPrice = true -} - -// AssetPriceCleared reports if the "assetPrice" edge to the AssetPrice entity was cleared. -func (m *DataSetMutation) AssetPriceCleared() bool { - return m.clearedassetPrice -} - -// RemoveAssetPriceIDs removes the "assetPrice" edge to the AssetPrice entity by IDs. -func (m *DataSetMutation) RemoveAssetPriceIDs(ids ...int) { - if m.removedassetPrice == nil { - m.removedassetPrice = make(map[int]struct{}) - } - for i := range ids { - delete(m.assetPrice, ids[i]) - m.removedassetPrice[ids[i]] = struct{}{} - } -} - -// RemovedAssetPrice returns the removed IDs of the "assetPrice" edge to the AssetPrice entity. -func (m *DataSetMutation) RemovedAssetPriceIDs() (ids []int) { - for id := range m.removedassetPrice { - ids = append(ids, id) - } - return -} - -// AssetPriceIDs returns the "assetPrice" edge IDs in the mutation. -func (m *DataSetMutation) AssetPriceIDs() (ids []int) { - for id := range m.assetPrice { - ids = append(ids, id) - } - return -} - -// ResetAssetPrice resets all changes to the "assetPrice" edge. -func (m *DataSetMutation) ResetAssetPrice() { - m.assetPrice = nil - m.clearedassetPrice = false - m.removedassetPrice = nil -} - -// Where appends a list predicates to the DataSetMutation builder. -func (m *DataSetMutation) Where(ps ...predicate.DataSet) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the DataSetMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *DataSetMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.DataSet, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *DataSetMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *DataSetMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (DataSet). -func (m *DataSetMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *DataSetMutation) Fields() []string { - fields := make([]string, 0, 1) - if m.name != nil { - fields = append(fields, dataset.FieldName) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *DataSetMutation) Field(name string) (ent.Value, bool) { - switch name { - case dataset.FieldName: - return m.Name() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *DataSetMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case dataset.FieldName: - return m.OldName(ctx) - } - return nil, fmt.Errorf("unknown DataSet field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *DataSetMutation) SetField(name string, value ent.Value) error { - switch name { - case dataset.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - } - return fmt.Errorf("unknown DataSet field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *DataSetMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *DataSetMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *DataSetMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown DataSet numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *DataSetMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *DataSetMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *DataSetMutation) ClearField(name string) error { - return fmt.Errorf("unknown DataSet nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *DataSetMutation) ResetField(name string) error { - switch name { - case dataset.FieldName: - m.ResetName() - return nil - } - return fmt.Errorf("unknown DataSet field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *DataSetMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.assetPrice != nil { - edges = append(edges, dataset.EdgeAssetPrice) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *DataSetMutation) AddedIDs(name string) []ent.Value { - switch name { - case dataset.EdgeAssetPrice: - ids := make([]ent.Value, 0, len(m.assetPrice)) - for id := range m.assetPrice { - ids = append(ids, id) - } - return ids - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *DataSetMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - if m.removedassetPrice != nil { - edges = append(edges, dataset.EdgeAssetPrice) - } - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *DataSetMutation) RemovedIDs(name string) []ent.Value { - switch name { - case dataset.EdgeAssetPrice: - ids := make([]ent.Value, 0, len(m.removedassetPrice)) - for id := range m.removedassetPrice { - ids = append(ids, id) - } - return ids - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *DataSetMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedassetPrice { - edges = append(edges, dataset.EdgeAssetPrice) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *DataSetMutation) EdgeCleared(name string) bool { - switch name { - case dataset.EdgeAssetPrice: - return m.clearedassetPrice - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *DataSetMutation) ClearEdge(name string) error { - switch name { - } - return fmt.Errorf("unknown DataSet unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *DataSetMutation) ResetEdge(name string) error { - switch name { - case dataset.EdgeAssetPrice: - m.ResetAssetPrice() - return nil - } - return fmt.Errorf("unknown DataSet edge %s", name) -} - // SignerMutation represents an operation that mutates the Signer nodes in the graph. type SignerMutation struct { config diff --git a/src/ent/predicate/predicate.go b/src/ent/predicate/predicate.go index 89fef449..93f5c0ca 100644 --- a/src/ent/predicate/predicate.go +++ b/src/ent/predicate/predicate.go @@ -20,8 +20,5 @@ func AssetPriceOrErr(p AssetPrice, err error) AssetPrice { } } -// DataSet is the predicate function for dataset builders. -type DataSet func(*sql.Selector) - // Signer is the predicate function for signer builders. type Signer func(*sql.Selector) diff --git a/src/ent/runtime.go b/src/ent/runtime.go index 919c8705..67cb6417 100644 --- a/src/ent/runtime.go +++ b/src/ent/runtime.go @@ -7,7 +7,6 @@ import ( "entgo.io/ent/schema/field" "github.com/KenshiTech/unchained/ent/assetprice" - "github.com/KenshiTech/unchained/ent/dataset" "github.com/KenshiTech/unchained/ent/schema" "github.com/KenshiTech/unchained/ent/signer" ) @@ -25,12 +24,6 @@ func init() { assetpriceDescSignature := assetpriceFields[3].Descriptor() // assetprice.SignatureValidator is a validator for the "signature" field. It is called by the builders before save. assetprice.SignatureValidator = assetpriceDescSignature.Validators[0].(func([]byte) error) - datasetFields := schema.DataSet{}.Fields() - _ = datasetFields - // datasetDescName is the schema descriptor for name field. - datasetDescName := datasetFields[0].Descriptor() - // dataset.NameValidator is a validator for the "name" field. It is called by the builders before save. - dataset.NameValidator = datasetDescName.Validators[0].(func(string) error) signerFields := schema.Signer{}.Fields() _ = signerFields // signerDescName is the schema descriptor for name field. diff --git a/src/ent/schema/assetprice.go b/src/ent/schema/assetprice.go index a7608bef..2322c452 100644 --- a/src/ent/schema/assetprice.go +++ b/src/ent/schema/assetprice.go @@ -17,19 +17,22 @@ type AssetPrice struct { // Fields of the DataSet. func (AssetPrice) Fields() []ent.Field { return []ent.Field{ - field.Uint64("block").Unique(), + field.Uint64("block"), field.Uint64("signersCount").Nillable().Optional(), field.String("price"). GoType(&big.Int{}). ValueScanner(field.TextValueScanner[*big.Int]{}), field.Bytes("signature").MaxLen(96), + field.String("asset").Optional(), + field.String("chain").Optional(), + field.String("pair").Optional(), } } // Edges of the DataSet. func (AssetPrice) Edges() []ent.Edge { return []ent.Edge{ - edge.To("dataSet", DataSet.Type).Required(), + // TODO: Make these required on next migrate edge.To("signers", Signer.Type).Required(), } } @@ -37,7 +40,6 @@ func (AssetPrice) Edges() []ent.Edge { // Edges of the DataSet. func (AssetPrice) Indexes() []ent.Index { return []ent.Index{ - index.Fields("block"). - Unique(), + index.Fields("block", "chain", "asset", "pair").Unique(), } } diff --git a/src/ent/schema/dataset.go b/src/ent/schema/dataset.go deleted file mode 100644 index f563b8c0..00000000 --- a/src/ent/schema/dataset.go +++ /dev/null @@ -1,35 +0,0 @@ -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" - "entgo.io/ent/schema/index" -) - -// DataSet holds the schema definition for the DataSet entity. -type DataSet struct { - ent.Schema -} - -// Fields of the DataSet. -func (DataSet) Fields() []ent.Field { - return []ent.Field{ - field.String("name").Unique().NotEmpty(), - } -} - -// Edges of the DataSet. -func (DataSet) Edges() []ent.Edge { - return []ent.Edge{ - edge.From("assetPrice", AssetPrice.Type).Ref("dataSet"), - } -} - -// Edges of the DataSet. -func (DataSet) Indexes() []ent.Index { - return []ent.Index{ - index.Fields("name"). - Unique(), - } -} diff --git a/src/ent/tx.go b/src/ent/tx.go index 58d363d3..c89db6b8 100644 --- a/src/ent/tx.go +++ b/src/ent/tx.go @@ -14,8 +14,6 @@ type Tx struct { config // AssetPrice is the client for interacting with the AssetPrice builders. AssetPrice *AssetPriceClient - // DataSet is the client for interacting with the DataSet builders. - DataSet *DataSetClient // Signer is the client for interacting with the Signer builders. Signer *SignerClient @@ -150,7 +148,6 @@ func (tx *Tx) Client() *Client { func (tx *Tx) init() { tx.AssetPrice = NewAssetPriceClient(tx.config) - tx.DataSet = NewDataSetClient(tx.config) tx.Signer = NewSignerClient(tx.config) } diff --git a/src/net/server.go b/src/net/server.go index 17b084d5..0cd35532 100644 --- a/src/net/server.go +++ b/src/net/server.go @@ -174,7 +174,8 @@ func processPriceReport(conn *websocket.Conn, messageType int, payload []byte) e message := []byte("signature.invalid") if ok { message = []byte("signature.accepted") - uniswap.RecordSignature(signature, signer, report.PriceInfo.Block) + // TODO: Only Ethereum is supported atm + uniswap.RecordSignature(signature, signer, report.PriceInfo) } err = conn.WriteMessage(messageType, append([]byte{2}, message...)) diff --git a/src/plugins/uniswap/uniswap.go b/src/plugins/uniswap/uniswap.go index 3a2d7a2e..991c5783 100644 --- a/src/plugins/uniswap/uniswap.go +++ b/src/plugins/uniswap/uniswap.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/big" + "strings" "sync" "time" @@ -22,19 +23,21 @@ import ( "github.com/go-co-op/gocron/v2" "github.com/gorilla/websocket" "github.com/vmihailenco/msgpack/v5" + "golang.org/x/text/cases" + "golang.org/x/text/language" bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381" lru "github.com/hashicorp/golang-lru/v2" ) -var DebouncedSaveSignatures func(key uint64, arg uint64) +var DebouncedSaveSignatures func(key AssetKey, arg datasets.PriceInfo) var signatureMutex *sync.Mutex -var priceCache *lru.Cache[uint64, big.Int] -var signatureCache *lru.Cache[uint64, []bls.Signature] -var aggregateCache *lru.Cache[uint64, bls12381.G1Affine] +var priceCache map[string]*lru.Cache[uint64, big.Int] +var signatureCache *lru.Cache[AssetKey, []bls.Signature] +var aggregateCache *lru.Cache[AssetKey, bls12381.G1Affine] -var twoOneNinetyTwo big.Int +var twoNinetySix big.Int var tenEighteen big.Int var tenEighteenF big.Float var lastBlock uint64 @@ -43,26 +46,61 @@ var lastPrice big.Int type Token struct { Name string `mapstructure:"name"` Pair string `mapstructure:"pair"` + Unit string `mapstructure:"unit"` + Symbol string `mapstructure:"symbol"` Delta int64 `mapstructure:"delta"` Invert bool `mapstructure:"invert"` } +type AssetKey struct { + Asset string + Pair string + Chain string + Block uint64 +} + // TODO: This needs to work with different datasets -func RecordSignature(signature bls12381.G1Affine, signer bls.Signer, block uint64) { +func RecordSignature( + signature bls12381.G1Affine, + signer bls.Signer, + info datasets.PriceInfo) { signatureMutex.Lock() defer signatureMutex.Unlock() + lruCache := priceCache[strings.ToLower(info.Pair)] + + if lruCache == nil { + return + } + // TODO: Needs optimization - if !priceCache.Contains(block) { + if !lruCache.Contains(info.Block) { var tokens []Token if err := config.Config.UnmarshalKey("plugins.uniswap.tokens", &tokens); err != nil { panic(err) } - eth := tokens[0] - blockNumber, _, err := GetPriceFromPair(eth.Pair, eth.Delta, eth.Invert) + var found Token + + for _, token := range tokens { + if strings.EqualFold(token.Pair, info.Pair) && + strings.EqualFold(token.Name, info.Asset) { + found = token + break + } + } + + if len(found.Pair) == 0 { + return + } + + blockNumber, _, err := GetPriceFromPair( + found.Pair, + found.Delta, + found.Invert, + ) if err != nil { return @@ -71,17 +109,24 @@ func RecordSignature(signature bls12381.G1Affine, signer bls.Signer, block uint6 lastBlock = *blockNumber } - if lastBlock-block > 16 { + if lastBlock-info.Block > 16 { return // Data too old } - cached, ok := signatureCache.Get(block) + key := AssetKey{ + Block: info.Block, + Asset: info.Asset, + Chain: info.Chain, + Pair: info.Pair, + } + + cached, ok := signatureCache.Get(key) packed := bls.Signature{Signature: signature, Signer: signer, Processed: false} if !ok { - signatureCache.Add(block, []bls.Signature{packed}) + signatureCache.Add(key, []bls.Signature{packed}) // TODO: This looks ugly - DebouncedSaveSignatures(block, block) + DebouncedSaveSignatures(key, info) return } @@ -92,21 +137,29 @@ func RecordSignature(signature bls12381.G1Affine, signer bls.Signer, block uint6 } cached = append(cached, packed) - signatureCache.Add(block, cached) + signatureCache.Add(key, cached) - DebouncedSaveSignatures(block, block) + DebouncedSaveSignatures(key, info) } -func SaveSignatures(block uint64) { +func SaveSignatures(info datasets.PriceInfo) { dbClient := db.GetClient() - price, ok := priceCache.Get(block) + lruCache := priceCache[strings.ToLower(info.Pair)] + price, ok := lruCache.Get(info.Block) if !ok { return } - signatures, ok := signatureCache.Get(block) + key := AssetKey{ + Block: info.Block, + Asset: info.Asset, + Chain: info.Chain, + Pair: info.Pair, + } + + signatures, ok := signatureCache.Get(key) if !ok { return @@ -114,18 +167,6 @@ func SaveSignatures(block uint64) { ctx := context.Background() - // TODO: Cache this - datasetId, err := dbClient.DataSet. - Create(). - SetName("uniswap::ethereum::ethereum"). - OnConflictColumns("name"). - UpdateName(). - ID(ctx) - - if err != nil { - panic(err) - } - var newSigners []bls.Signer var newSignatures []bls12381.G1Affine var keys [][]byte @@ -139,7 +180,7 @@ func SaveSignatures(block uint64) { } } - err = dbClient.Signer.MapCreateBulk(newSigners, func(sc *ent.SignerCreate, i int) { + err := dbClient.Signer.MapCreateBulk(newSigners, func(sc *ent.SignerCreate, i int) { signer := newSigners[i] sc.SetName(signer.Name). SetKey(signer.PublicKey[:]). @@ -168,7 +209,7 @@ func SaveSignatures(block uint64) { } var aggregate bls12381.G1Affine - currentAggregate, ok := aggregateCache.Get(block) + currentAggregate, ok := aggregateCache.Get(key) if ok { newSignatures = append(newSignatures, currentAggregate) @@ -184,13 +225,15 @@ func SaveSignatures(block uint64) { err = dbClient.AssetPrice. Create(). - SetBlock(block). + SetPair(info.Pair). + SetAsset(info.Asset). + SetChain(info.Chain). + SetBlock(info.Block). SetPrice(&price). SetSignersCount(uint64(len(signatures))). SetSignature(signatureBytes[:]). - AddDataSetIDs(datasetId). AddSignerIDs(signerIds...). - OnConflictColumns("block"). + OnConflictColumns("block", "chain", "asset", "pair"). UpdateNewValues(). Exec(ctx) @@ -202,32 +245,36 @@ func SaveSignatures(block uint64) { signature.Processed = true } - aggregateCache.Add(block, aggregate) - + aggregateCache.Add(key, aggregate) } -// TODO: Each pair should have its own LRU-Cache -func GetPriceFromCache(block uint64) (big.Int, bool) { - return priceCache.Get(block) +func GetPriceFromCache(block uint64, pair string) (big.Int, bool) { + lruCache := priceCache[strings.ToLower(pair)] + return lruCache.Get(block) } -func GetPriceFromPair(pairAddr string, decimalDif int64, inverse bool) (*uint64, *big.Int, error) { +func GetBlockNumber() (*uint64, error) { blockNumber, err := ethereum.GetBlockNumber() if err != nil { ethereum.RefreshRPC() - return nil, nil, err + return nil, err } - if blockNumber == lastBlock { - return &blockNumber, &lastPrice, nil - } + return &blockNumber, nil +} + +func GetPriceAtBlockFromPair( + blockNumber uint64, + pairAddr string, + decimalDif int64, + inverse bool) (*big.Int, error) { pair, err := ethereum.GetNewUniV3Contract(pairAddr, false) if err != nil { ethereum.RefreshRPC() - return nil, nil, err + return nil, err } data, err := pair.Slot0( @@ -235,38 +282,80 @@ func GetPriceFromPair(pairAddr string, decimalDif int64, inverse bool) (*uint64, BlockNumber: big.NewInt(int64(blockNumber)), }) + if err != nil { + ethereum.RefreshRPC() + return nil, err + } + + lastPrice = *priceFromSqrtX96(data.SqrtPriceX96, decimalDif, inverse) + lruCache := priceCache[strings.ToLower(pairAddr)] + lruCache.Add(blockNumber, lastPrice) + + return &lastPrice, nil +} + +func GetPriceFromPair( + pairAddr string, + decimalDif int64, + inverse bool) (*uint64, *big.Int, error) { + + blockNumber, err := ethereum.GetBlockNumber() + if err != nil { ethereum.RefreshRPC() return nil, nil, err } - lastPrice = *priceFromSqrtX96(data.SqrtPriceX96, 6, true) - priceCache.Add(blockNumber, lastPrice) + lastPrice, err := GetPriceAtBlockFromPair( + blockNumber, + pairAddr, + decimalDif, + inverse) - return &blockNumber, &lastPrice, nil + return &blockNumber, lastPrice, err } func priceFromSqrtX96(sqrtPriceX96 *big.Int, decimalDif int64, inverse bool) *big.Int { - var priceX96 big.Int - var raw big.Int + var decimalFix big.Int + var sqrtPrice big.Int + var rawPrice big.Int var price big.Int var factor big.Int - // const raw = (fetchedSqrtPriceX96**2 / 2**192) * 10**6; - priceX96.Exp(sqrtPriceX96, big.NewInt(2), nil) - raw.Div(&priceX96, &twoOneNinetyTwo) + decimalFix.Mul(sqrtPriceX96, &tenEighteen) + sqrtPrice.Div(&decimalFix, &twoNinetySix) + rawPrice.Exp(&sqrtPrice, big.NewInt(2), nil) if inverse { - factor.Exp(big.NewInt(10), big.NewInt(36-decimalDif), nil) - price.Div(&factor, &raw) + factor.Exp(big.NewInt(10), big.NewInt(72-decimalDif), nil) + price.Div(&factor, &rawPrice) } else { // TODO: needs work - factor.Exp(big.NewInt(10), big.NewInt(decimalDif), nil) - price.Div(&raw, &factor) + factor.Exp(big.NewInt(10), big.NewInt(18-decimalDif), nil) + price.Div(&rawPrice, &factor) } + return &price } +func Setup() { + var tokens []Token + + err := config.Config.UnmarshalKey("plugins.uniswap.tokens", &tokens) + + if err != nil { + panic(err) + } + + for _, token := range tokens { + priceCache[strings.ToLower(token.Pair)], err = lru.New[uint64, big.Int](24) + + if err != nil { + panic(err) + } + } +} + func Start() { scheduler, err := gocron.NewScheduler() @@ -280,7 +369,15 @@ func Start() { panic(err) } - eth := tokens[0] + caser := cases.Title(language.English, cases.NoLower) + + for _, token := range tokens { + priceCache[strings.ToLower(token.Pair)], err = lru.New[uint64, big.Int](24) + + if err != nil { + panic(err) + } + } _, err = scheduler.NewJob( gocron.DurationJob(5*time.Second), @@ -291,7 +388,7 @@ func Start() { return } - blockNumber, price, err := GetPriceFromPair(eth.Pair, eth.Delta, eth.Invert) + blockNumber, err := GetBlockNumber() if err != nil { return @@ -303,41 +400,62 @@ func Start() { lastBlock = *blockNumber - var priceF big.Float - priceF.Quo(new(big.Float).SetInt(price), &tenEighteenF) + for _, token := range tokens { - priceStr := fmt.Sprintf("$%.18f", &priceF) + price, err := GetPriceAtBlockFromPair( + *blockNumber, + token.Pair, + token.Delta, + token.Invert, + ) - log.Logger. - With("Block", *blockNumber). - With("Price", priceStr). - Info("Ethereum") + if err != nil { + return + } - priceInfo := datasets.PriceInfo{Price: *price, Block: *blockNumber} - toHash, err := msgpack.Marshal(&priceInfo) + var priceF big.Float + priceF.Quo(new(big.Float).SetInt(price), &tenEighteenF) - if err != nil { - panic(err) - } + priceStr := fmt.Sprintf("%.18f %s", &priceF, token.Unit) - signature, _ := bls.Sign(*bls.ClientSecretKey, toHash) - compressedSignature := signature.Bytes() + log.Logger. + With("Block", *blockNumber). + With("Price", priceStr). + Info(caser.String(token.Name)) - priceReport := datasets.PriceReport{ - PriceInfo: priceInfo, - Signature: compressedSignature, - } + priceInfo := datasets.PriceInfo{ + Price: *price, + Block: *blockNumber, + Chain: "ethereum", + Pair: strings.ToLower(token.Pair), + Asset: strings.ToLower(token.Name), + } - payload, err := msgpack.Marshal(&priceReport) + toHash, err := msgpack.Marshal(&priceInfo) - if err != nil { - panic(err) - } + if err != nil { + panic(err) + } - if !client.IsClientSocketClosed { - client.Client.WriteMessage(websocket.BinaryMessage, append([]byte{1, 0}, payload...)) - } + signature, _ := bls.Sign(*bls.ClientSecretKey, toHash) + compressedSignature := signature.Bytes() + + priceReport := datasets.PriceReport{ + PriceInfo: priceInfo, + Signature: compressedSignature, + } + + payload, err := msgpack.Marshal(&priceReport) + if err != nil { + panic(err) + } + + if !client.IsClientSocketClosed { + client.Client.WriteMessage(websocket.BinaryMessage, append([]byte{1, 0}, payload...)) + } + + } }, ), ) @@ -351,27 +469,24 @@ func Start() { func init() { - DebouncedSaveSignatures = utils.Debounce[uint64, uint64](5*time.Second, SaveSignatures) + DebouncedSaveSignatures = utils.Debounce[AssetKey, datasets.PriceInfo](5*time.Second, SaveSignatures) signatureMutex = new(sync.Mutex) - twoOneNinetyTwo.Exp(big.NewInt(2), big.NewInt(192), nil) + twoNinetySix.Exp(big.NewInt(2), big.NewInt(96), nil) tenEighteen.Exp(big.NewInt(10), big.NewInt(18), nil) tenEighteenF.SetInt(&tenEighteen) - var err error - priceCache, err = lru.New[uint64, big.Int](24) + // TODO: Should use AssetKey + priceCache = make(map[string]*lru.Cache[uint64, big.Int]) - if err != nil { - panic(err) - } - - signatureCache, err = lru.New[uint64, []bls.Signature](24) + var err error + signatureCache, err = lru.New[AssetKey, []bls.Signature](24) if err != nil { panic(err) } - aggregateCache, err = lru.New[uint64, bls12381.G1Affine](24) + aggregateCache, err = lru.New[AssetKey, bls12381.G1Affine](24) if err != nil { panic(err) From 9895eeb42528d5a3cc0a6172a08c5eda961f3539 Mon Sep 17 00:00:00 2001 From: Pouya Date: Tue, 20 Feb 2024 11:28:42 +0100 Subject: [PATCH 2/2] Fix template files --- conf.broker.yaml.template | 14 ++++++++++ conf.remote.yaml.template | 14 ++++++++++ conf.worker.yaml.template | 14 ++++++++++ quickstart.md | 59 +++++++++++---------------------------- 4 files changed, 58 insertions(+), 43 deletions(-) diff --git a/conf.broker.yaml.template b/conf.broker.yaml.template index a26bc484..00bc34a6 100644 --- a/conf.broker.yaml.template +++ b/conf.broker.yaml.template @@ -12,8 +12,22 @@ plugins: - https://eth.llamarpc.com - wss://ethereum.publicnode.com - https://eth.rpc.blxrbdn.com + tokens: - name: ethereum pair: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" delta: 6 invert: true + unit: USDT + + - name: arbitrum + pair: "0x59354356Ec5d56306791873f567d61EBf11dfbD5" + delta: 0 + invert: false + unit: ETH + + - name: bitcoin + pair: "0x9db9e0e53058c89e5b94e29621a205198648425b" + delta: 2 + invert: false + unit: USDT diff --git a/conf.remote.yaml.template b/conf.remote.yaml.template index a26bc484..00bc34a6 100644 --- a/conf.remote.yaml.template +++ b/conf.remote.yaml.template @@ -12,8 +12,22 @@ plugins: - https://eth.llamarpc.com - wss://ethereum.publicnode.com - https://eth.rpc.blxrbdn.com + tokens: - name: ethereum pair: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" delta: 6 invert: true + unit: USDT + + - name: arbitrum + pair: "0x59354356Ec5d56306791873f567d61EBf11dfbD5" + delta: 0 + invert: false + unit: ETH + + - name: bitcoin + pair: "0x9db9e0e53058c89e5b94e29621a205198648425b" + delta: 2 + invert: false + unit: USDT diff --git a/conf.worker.yaml.template b/conf.worker.yaml.template index 43c086a4..000c8838 100644 --- a/conf.worker.yaml.template +++ b/conf.worker.yaml.template @@ -9,8 +9,22 @@ plugins: - https://eth.llamarpc.com - wss://ethereum.publicnode.com - https://eth.rpc.blxrbdn.com + tokens: - name: ethereum pair: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" delta: 6 invert: true + unit: USDT + + - name: arbitrum + pair: "0x59354356Ec5d56306791873f567d61EBf11dfbD5" + delta: 0 + invert: false + unit: ETH + + - name: bitcoin + pair: "0x9db9e0e53058c89e5b94e29621a205198648425b" + delta: 2 + invert: false + unit: USDT diff --git a/quickstart.md b/quickstart.md index 77cc99c2..be988bd4 100644 --- a/quickstart.md +++ b/quickstart.md @@ -207,11 +207,25 @@ plugins: - https://eth.llamarpc.com - wss://ethereum.publicnode.com - https://eth.rpc.blxrbdn.com + tokens: - name: ethereum pair: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" delta: 6 invert: true + unit: USDT + + - name: arbitrum + pair: "0x59354356Ec5d56306791873f567d61EBf11dfbD5" + delta: 0 + invert: false + unit: ETH + + - name: bitcoin + pair: "0x9db9e0e53058c89e5b94e29621a205198648425b" + delta: 2 + invert: false + unit: USDT ``` Save the above configuration in a file named `conf.yaml` on your system and make @@ -222,26 +236,13 @@ the following modifications if required: messages. - `name`: This name will be associated with your validator node, and is published to all peers. -- `plugins.rpc.ethereum`: Unchained testnet has automatic RPC rotation and renewal when +- `plugins.uniswap.rpc.ethereum`: Unchained testnet has automatic RPC rotation and renewal when issues are detected with the RPC connection. You can find a list of Ethereum RPC nodes on [Chainlist](https://chainlist.org/chain/1). +- `plugins.uniswap.tokens`: UniSwap V3 pool information for fetching and indexing token prices. You can also use RPC nodes that start with `wss://` instead of `https://`. -## Migrations / Database Initialization - -Note: Skip this step if you're running a worker node. - -Before running the Unchained client, you need to get your database schema ready -for storing Unchained data. To do so, you should run: - -```bash -unchained postgres migrate conf.yaml -``` - -You'll need to run this command again if you're installing a new version of the -client that makes changes to the Unchained data structure. - ## Starting an Unchained worker node To start a worker node and join the Unchained network, you need to run the @@ -254,34 +255,6 @@ unchained.OS.ARCH worker **Note: if you are running the node for the first time, Unchained will generate a random secret key. This key will be saved to the `secrets.yaml` file. It is your responsibility to keep this file safe.** -## Max Open Sockets - -Depending on your OS and OS configuration, you might run into issues if you have -too many peers connected. Follow the guides below to increase the maximum open -connections limit on your OS. - -### MacOS - -To increase the limit on MacOS, run these commands: - -```bash -sudo sysctl kern.maxfiles=2000000 kern.maxfilesperproc=2000000 -echo "ulimit -Hn 2000000" >> ~/.zshrc -echo "ulimit -Sn 2000000" >> ~/.zshrc -source ~/.zshrc -``` - -### Linux - -To increase the limit on Linux, run these commands: - -```bash -sudo sysctl -w fs.nr_open=33554432 -echo "ulimit -Hn 33554432" >> ~/.bashrc -echo "ulimit -Sn 33554432" >> ~/.bashrc -source ~/.bashrc -``` - ## Help Running the following command in CMD or terminal should give you a list of