diff --git a/.air.toml b/.air.toml deleted file mode 100644 index 5e0318c..0000000 --- a/.air.toml +++ /dev/null @@ -1,37 +0,0 @@ -root = "." -testdata_dir = "testdata" -tmp_dir = "tmp" - -[build] - args_bin = [] - bin = "./tmp/main" - cmd = "go build -o ./tmp/main ." - delay = 1000 - exclude_dir = ["assets", "tmp", "vendor", "testdata"] - exclude_file = [] - exclude_regex = ["_test.go"] - exclude_unchanged = false - follow_symlink = false - full_bin = "" - include_dir = [] - include_ext = ["go", "tpl", "tmpl", "html"] - kill_delay = "0s" - log = "build-errors.log" - send_interrupt = false - stop_on_error = true - -[color] - app = "" - build = "yellow" - main = "magenta" - runner = "green" - watcher = "cyan" - -[log] - time = false - -[misc] - clean_on_exit = false - -[screen] - clear_on_rebuild = false diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..57f929d --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,32 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: virtuacoin-wallet + +on: + push: + branches: [ "main" ] + +jobs: + + main: + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: shachindra/virtuacoin-wallet:latest diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index da56bfa..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: "Lint" -on: ["push", "pull_request"] - -jobs: - ci: - name: "Run go vet and staticcheck" - runs-on: ubuntu-latest - container: golang:buster - steps: - - uses: actions/checkout@v1 - - run: "go vet ./..." - - uses: dominikh/staticcheck-action@v1.1.0 - with: - install-go: false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 28a7141..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: "Test" - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - test: - runs-on: ubuntu-latest - container: golang:buster - env: - DB_HOST: postgres - DB_USERNAME: postgres - DB_PASSWORD: postgres - DB_NAME: postgres - DB_PORT: 5432 - JWT_PRIVATE_KEY: aaaa - VOTER_EULA: TODO VOTER EULA - AUTH_EULA: TODO AUTH EULA - NETWORK_CHAIN_ID_POLYGON: 80001 - NETWORK_NAME_POLYGON: polygon - NETWORK_PATH_POLYGON: m/44H/60H/0H/0/0 - NETWORK_RPC_URL_POLYGON: ${{ secrets.NETWORK_RPC_URL_POLYGON }} - NETWORK_CHAIN_ID_ETHEREUM: 1 - NETWORK_NAME_ETHEREUM: ethereum - NETWORK_PATH_ETHEREUM: m/44H/60H/0H/0/0 - NETWORK_RPC_URL_ETHEREUM: ${{ secrets.NETWORK_RPC_URL_ETHEREUM }} - TOKEN: aa - - services: - postgres: - image: postgres - env: - POSTGRES_PASSWORD: postgres - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - - steps: - - name: Install gotestsum - run: go install gotest.tools/gotestsum@latest - - uses: actions/checkout@v2 - - name: Build - run: go build -v ./... - - name: Test - run: LOAD_CONFIG_FILE=false gotestsum diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index b298e2a..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,26 +0,0 @@ -image: - file: .gitpod/Dockerfile -tasks: - - name: golang live - init: | - go install gotest.tools/gotestsum@latest - go get && go build -o build/superiad - command: | - docker run --name="superiad" --rm -d -p 5432:5432 \ - -e POSTGRES_PASSWORD=superiad \ - -e POSTGRES_USER=superiad \ - -e POSTGRES_DB=superiad \ - postgres -c log_statement=all - sleep 12 - gp sync-done db - cp sample.env .env - air - - - name: postgres shell - command: | - gp sync-await db - docker exec -it superiad psql -U superiad - -vscode: - extensions: - - golang.go \ No newline at end of file diff --git a/.gitpod/Dockerfile b/.gitpod/Dockerfile deleted file mode 100644 index 2533f03..0000000 --- a/.gitpod/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM gitpod/workspace-full - -RUN sudo curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..47cecb6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:alpine as builder +WORKDIR /app +COPY go.mod . +COPY go.sum . +RUN apk add build-base +RUN go mod download +COPY . . +RUN apk add --no-cache git && go build -o wallet . && apk del git + +FROM alpine +WORKDIR /app +COPY --from=builder /app/wallet . +CMD [ "./wallet" ] \ No newline at end of file diff --git a/README.md b/README.md index d83d928..07cb910 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,29 @@ -# Superiad +# virtuacoin_wallet -A custodial wallet, covering all primary functions. -This custodial wallet provides these features +Self custodial wallet, covering all primary functions. +Wallet provides these features -- ERC721 - - approve - - approveAll - - transfer - - checkbalance - - isowner +- Native Asset for the Configured Network + - [ ] transfer + - [ ] checkbalance + - [ ] fetchwallet + - [ ] signMessage + - [ ] verifySignature - ERC20 - - transfer - - checkbalance -- Native - - transfer - - checkbalance - - fetchwallet - - signMessage - - verifySignature - -This system also supports locking the wallet using which the user can lock his funds. + - [ ] transfer + - [ ] checkbalance +- ERC721 + - [ ] approve + - [ ] approveAll + - [ ] transfer + - [ ] checkbalance + - [ ] burn +- VirtuaCoinNFT + - [ ] delegateAssetCreation + - [ ] grantRole + - [ ] burn -## Postgres for development +## Redis for development ```bash - docker run --name="superiad" --rm -d -p 5432:5432 \ - -e POSTGRES_PASSWORD=superiad \ - -e POSTGRES_USER=superiad \ - -e POSTGRES_DB=superiad \ - postgres -c log_statement=all -``` \ No newline at end of file + podman run --name="virtuacoin-wallet-redis" --rm -d -p 6379:6379 redis -c log_statement=all +``` diff --git a/api/api.go b/api/api.go index 09f94b2..1e5b69e 100644 --- a/api/api.go +++ b/api/api.go @@ -1,8 +1,7 @@ package api import ( - "github.com/TheLazarusNetwork/superiad/api/middleware/auth/tokenmiddleware" - v1 "github.com/TheLazarusNetwork/superiad/api/v1" + v1 "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1" "github.com/gin-gonic/gin" ) @@ -11,7 +10,6 @@ import ( func ApplyRoutes(r *gin.Engine) { api := r.Group("/api") { - api.Use(tokenmiddleware.ApiAuth) v1.ApplyRoutes(api) } } diff --git a/api/middleware/auth/tokenmiddleware/token.go b/api/middleware/auth/tokenmiddleware/token.go deleted file mode 100644 index 600643d..0000000 --- a/api/middleware/auth/tokenmiddleware/token.go +++ /dev/null @@ -1,45 +0,0 @@ -package tokenmiddleware - -import ( - "errors" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - - "github.com/gin-gonic/gin" -) - -var ( - ErrAuthHeaderMissing = errors.New("authorization header is required") -) - -func ApiAuth(c *gin.Context) { - var headers GenericAuthHeaders - err := c.BindHeader(&headers) - token := headers.Authorization - - if err != nil { - logValidationFailed(token, err) - c.Abort() - return - } - if headers.Authorization == "" { - logValidationFailed(token, err) - httpo.NewErrorResponse(http.StatusBadRequest, ErrAuthHeaderMissing.Error()).SendD(c) - c.Abort() - return - } - - if token != envconfig.EnvVars.TOKEN { - logValidationFailed(token, err) - httpo.NewErrorResponse(http.StatusForbidden, "token is invalid").SendD(c) - c.Abort() - return - } -} - -func logValidationFailed(token string, err error) { - logo.Warnf("validation failed with token %v, error: %s", token, err) -} diff --git a/api/middleware/auth/tokenmiddleware/token_test.go b/api/middleware/auth/tokenmiddleware/token_test.go deleted file mode 100644 index ae7073e..0000000 --- a/api/middleware/auth/tokenmiddleware/token_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package tokenmiddleware - -import ( - "net/http" - "net/http/httptest" - "testing" - - "github.com/TheLazarusNetwork/superiad/config/envconfig" - "github.com/gin-gonic/gin" - "github.com/stretchr/testify/assert" -) - -func Test_APIAUTH(t *testing.T) { - envconfig.InitEnvVars() - - correctToken := envconfig.EnvVars.TOKEN - t.Run("success if token is valid", func(t *testing.T) { - rr := httptest.NewRecorder() - c, _ := gin.CreateTestContext(rr) - req, e := http.NewRequest("GET", "", nil) - req.Header.Add("Authorization", correctToken) - if e != nil { - t.Fatal(e) - } - c.Request = req - ApiAuth(c) - assert.Equal(t, 200, rr.Result().StatusCode) - }) - - t.Run("fail if token is notvalid", func(t *testing.T) { - rr := httptest.NewRecorder() - c, _ := gin.CreateTestContext(rr) - req, e := http.NewRequest("GET", "", nil) - req.Header.Add("Authorization", correctToken+"extra data which will invalidate token") - if e != nil { - t.Fatal(e) - } - c.Request = req - ApiAuth(c) - assert.Equal(t, http.StatusForbidden, rr.Result().StatusCode) - }) -} diff --git a/api/middleware/auth/tokenmiddleware/types.go b/api/middleware/auth/tokenmiddleware/types.go deleted file mode 100644 index b5ffa43..0000000 --- a/api/middleware/auth/tokenmiddleware/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package tokenmiddleware - -type GenericAuthHeaders struct { - Authorization string `binding:"required"` -} diff --git a/api/middleware/onlyunlockedmiddleware/onlylockedmiddleware.go b/api/middleware/onlyunlockedmiddleware/onlylockedmiddleware.go deleted file mode 100644 index 8775214..0000000 --- a/api/middleware/onlyunlockedmiddleware/onlylockedmiddleware.go +++ /dev/null @@ -1,56 +0,0 @@ -package onlyunlockedmiddleware - -import ( - "bytes" - "errors" - "io" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/gin-gonic/gin" - "gorm.io/gorm" -) - -func OnlyUnlocked() gin.HandlerFunc { - return func(c *gin.Context) { - ByteBody, err := io.ReadAll(c.Request.Body) - if err != nil { - httpo.NewErrorResponse(500, "failed to read body").SendD(c) - logo.Errorf("failed to read body from request: %s", err) - c.Abort() - return - } - c.Request.Body = io.NopCloser(bytes.NewBuffer(ByteBody)) - var req AccessRequest - err = c.ShouldBindJSON(&req) - if err != nil { - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - c.Abort() - return - } - _user, err := user.GetUser(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - c.Abort() - return - } - - httpo.NewErrorResponse(500, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user with id: %s, err: %s", req.UserId, err) - c.Abort() - return - } - - if _user.IsUserLocked { - httpo.NewErrorResponse(httpo.UserLocked, "cannot perform this operation when user is locked").Send(c, http.StatusForbidden) - c.Abort() - return - } - c.Request.Body = io.NopCloser(bytes.NewBuffer(ByteBody)) - - c.Next() - } -} diff --git a/api/middleware/onlyunlockedmiddleware/types.go b/api/middleware/onlyunlockedmiddleware/types.go deleted file mode 100644 index 86c5ac2..0000000 --- a/api/middleware/onlyunlockedmiddleware/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package onlyunlockedmiddleware - -type AccessRequest struct { - UserId string `json:"userId" binding:"required"` -} diff --git a/api/v1/bsc/approve/approve.go b/api/v1/bsc/approve/approve.go new file mode 100644 index 0000000..499980f --- /dev/null +++ b/api/v1/bsc/approve/approve.go @@ -0,0 +1,49 @@ +package approve + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/approve") + { + + g.POST("", approveWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := ApprovePayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func approveWithSalt(c *gin.Context) { + network := "bsc" + var req ApproveWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("Invalid request body:%s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + + hash, err := bsc.ApproveERC721(req.Mnemonic, common.HexToAddress(req.ToAddress), common.HexToAddress(req.ContractAddress), *big.NewInt(req.TokenId)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve").SendD(c) + logo.Errorf("failed to approve to: %v from wallet of userId: %v, network: %v, contractAddr: %v, tokenId: %v, error: %s", req.ToAddress, + req.WalletAddress, network, req.ContractAddress, req.TokenId, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) + +} diff --git a/api/v1/bsc/approve/approve_test.go b/api/v1/bsc/approve/approve_test.go new file mode 100644 index 0000000..3020ba6 --- /dev/null +++ b/api/v1/bsc/approve/approve_test.go @@ -0,0 +1,121 @@ +package approve + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_Approve(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + type network struct { + name string + chainId int64 + erc20Address string + erc721Address string + } + networks := []network{ + { + name: "bsc", + chainId: 80001, + erc721Address: "0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e", + }, { + name: "ethereum", + chainId: 1, + erc721Address: "0x514910771af9ca656af840dff83e8264ecf986ca", + }, + } + + t.Run("Native token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := ApproveWithSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ToAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ContractAddress: n.erc721Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http.NewRequest("GET", "/", bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + approveWithSalt(c) + + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + + t.Run("ERC20 Token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := ApproveWithSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ToAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ContractAddress: n.erc721Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + reqUrl := fmt.Sprintf("/?erc20Address=%v", n.erc20Address) + httpReq, e := http.NewRequest("GET", reqUrl, bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + approveWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + t.Run("ERC721 Token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := ApproveWithSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ToAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ContractAddress: n.erc721Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + reqUrl := fmt.Sprintf("/?erc721Address=%v", n.erc721Address) + httpReq, e := http. + NewRequest("GET", reqUrl, + bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + approveWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + +} diff --git a/api/v1/bsc/approve/types.go b/api/v1/bsc/approve/types.go new file mode 100644 index 0000000..4486de9 --- /dev/null +++ b/api/v1/bsc/approve/types.go @@ -0,0 +1,14 @@ +package approve + +type ApproveWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ToAddress string `json:"toAddress" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} + +type ApprovePayload struct { + TrasactionHash string +} diff --git a/api/v1/bsc/approveAll/approveall.go b/api/v1/bsc/approveAll/approveall.go new file mode 100644 index 0000000..f152530 --- /dev/null +++ b/api/v1/bsc/approveAll/approveall.go @@ -0,0 +1,46 @@ +package approveall + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/approve-all") + { + g.POST("", approveAllWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := TransferPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func approveAllWithSalt(c *gin.Context) { + network := "bsc" + var req ApproveAllWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + hash, err := bsc.SetAprovalForAllErc721(req.Mnemonic, common.HexToAddress(req.OperatorAddress), common.HexToAddress(req.ContractAddress), req.Approved) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve all").SendD(c) + logo.Errorf("failed to approve all to operator: %v from wallet of userId: %v, network: %v, contractAddr: %v, error: %s", req.OperatorAddress, + req.WalletAddress, network, req.ContractAddress, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) +} diff --git a/api/v1/bsc/approveAll/approveall_test.go b/api/v1/bsc/approveAll/approveall_test.go new file mode 100644 index 0000000..d79c1cb --- /dev/null +++ b/api/v1/bsc/approveAll/approveall_test.go @@ -0,0 +1,120 @@ +package approveall + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_Approve(t *testing.T) { + envconfig.InitEnvVars() + appinit.Init() + gin.SetMode(gin.TestMode) + + type network struct { + name string + chainId int64 + erc20Address string + erc721Address string + } + networks := []network{ + { + name: "bsc", + chainId: 80001, + erc721Address: "0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e", + }, { + name: "ethereum", + chainId: 1, + erc721Address: "0x514910771af9ca656af840dff83e8264ecf986ca", + }, + } + + t.Run("Native token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := ApproveAllRequest{ + UserId: "60", + OperatorAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ContractAddress: n.erc721Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http.NewRequest("GET", "/", bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + approveAllWithSalt(c) + + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + + t.Run("ERC20 Token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := ApproveAllRequest{ + UserId: "60", + OperatorAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ContractAddress: n.erc721Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + reqUrl := fmt.Sprintf("/?erc20Address=%v", n.erc20Address) + httpReq, e := http.NewRequest("GET", reqUrl, bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + approveAllWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + t.Run("ERC721 Token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := ApproveAllRequest{ + UserId: "60", + OperatorAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + ContractAddress: n.erc721Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + reqUrl := fmt.Sprintf("/?erc721Address=%v", n.erc721Address) + httpReq, e := http. + NewRequest("GET", reqUrl, + bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + approveAllWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + +} diff --git a/api/v1/matic/approveAll/types.go b/api/v1/bsc/approveAll/types.go similarity index 50% rename from api/v1/matic/approveAll/types.go rename to api/v1/bsc/approveAll/types.go index 47e9947..a7e2ed0 100644 --- a/api/v1/matic/approveAll/types.go +++ b/api/v1/bsc/approveAll/types.go @@ -7,6 +7,14 @@ type ApproveAllRequest struct { Approved bool `json:"approved" binding:"required"` } +type ApproveAllWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + OperatorAddress string `json:"operatorAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + Approved bool `json:"approved" binding:"required"` +} + type TransferPayload struct { TrasactionHash string } diff --git a/api/v1/bsc/bsc.go b/api/v1/bsc/bsc.go new file mode 100644 index 0000000..b8c9ef8 --- /dev/null +++ b/api/v1/bsc/bsc.go @@ -0,0 +1,29 @@ +package bsc + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/approve" + approveall "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/approveAll" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/checkbalance" + signmessage "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/signMessage" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/transfer" + verifysignature "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/verifySignature" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/virtuacoinnft" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes Use the given Routes +func ApplyRoutes(r *gin.RouterGroup) { + v1 := r.Group("/bsc") + { + checkbalance.ApplyRoutes(v1) + verifysignature.ApplyRoutes(v1) + + signmessage.ApplyRoutes(v1) + // burn.ApplyRoutes(v1) + transfer.ApplyRoutes(v1) + approve.ApplyRoutes(v1) + approveall.ApplyRoutes(v1) + virtuacoinnft.ApplyRoutes(v1) + } +} diff --git a/api/v1/bsc/burn/burn.go b/api/v1/bsc/burn/burn.go new file mode 100644 index 0000000..c3b83c1 --- /dev/null +++ b/api/v1/bsc/burn/burn.go @@ -0,0 +1,15 @@ +package burn + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/burn/burn_erc721" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/burn") + { + burn_erc721.ApplyRoutes(g) + } +} diff --git a/api/v1/bsc/burn/burn_erc721/burn_erc721.go b/api/v1/bsc/burn/burn_erc721/burn_erc721.go new file mode 100644 index 0000000..636471e --- /dev/null +++ b/api/v1/bsc/burn/burn_erc721/burn_erc721.go @@ -0,0 +1,46 @@ +package burn_erc721 + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc721") + { + g.POST("", burnWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := BurnPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func burnWithSalt(c *gin.Context) { + network := "bsc" + var req BurnWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("Invalid request body:%s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + + hash, err := bsc.BurnERC721(req.Mnemonic, common.HexToAddress(req.ContractAddress), *big.NewInt(req.TokenId)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve").SendD(c) + logo.Errorf("failed to burn tokenId: %v from wallet of: %v, network: %v, contractAddr: %v, error: %s", req.TokenId, req.WalletAddress, network, req.ContractAddress, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) +} diff --git a/api/v1/bsc/burn/burn_erc721/types.go b/api/v1/bsc/burn/burn_erc721/types.go new file mode 100644 index 0000000..61c8752 --- /dev/null +++ b/api/v1/bsc/burn/burn_erc721/types.go @@ -0,0 +1,13 @@ +package burn_erc721 + +type BurnWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} + +type BurnPayload struct { + TrasactionHash string +} diff --git a/api/v1/matic/checkbalance/checkbalance.go b/api/v1/bsc/checkbalance/checkbalance.go similarity index 50% rename from api/v1/matic/checkbalance/checkbalance.go rename to api/v1/bsc/checkbalance/checkbalance.go index 3c2fd23..33b731e 100644 --- a/api/v1/matic/checkbalance/checkbalance.go +++ b/api/v1/bsc/checkbalance/checkbalance.go @@ -1,9 +1,9 @@ package checkbalance import ( - "github.com/TheLazarusNetwork/superiad/api/v1/matic/checkbalance/checkbalance_erc20" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/checkbalance/checkbalance_erc721" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/checkbalance/checkbalance_native" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/checkbalance/checkbalance_erc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/checkbalance/checkbalance_erc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/checkbalance/checkbalance_native" "github.com/gin-gonic/gin" ) @@ -12,7 +12,6 @@ import ( func ApplyRoutes(r *gin.RouterGroup) { g := r.Group("/checkbalance") { - checkbalance_erc20.ApplyRoutes(g) checkbalance_erc721.ApplyRoutes(g) checkbalance_native.ApplyRoutes(g) diff --git a/api/v1/bsc/checkbalance/checkbalance_erc20/erc20.go b/api/v1/bsc/checkbalance/checkbalance_erc20/erc20.go new file mode 100644 index 0000000..0eb6cb7 --- /dev/null +++ b/api/v1/bsc/checkbalance/checkbalance_erc20/erc20.go @@ -0,0 +1,46 @@ +package checkbalance_erc20 + +import ( + "net/http" + "strconv" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc20") + { + g.GET("/:contractAddress/:walletAddress", erc20CheckBalanceSalt) + } +} + +func erc20CheckBalanceSalt(c *gin.Context) { + paramContractAddress := c.Param("contractAddress") + paramWalletAddress := c.Param("walletAddress") + if len(paramWalletAddress) <= 0 { + httpo.NewErrorResponse(http.StatusBadRequest, "valid wallet address is required").SendD(c) + return + } + network := "bsc" + + balance, err := bsc.GetERC20BalanceInDecimalsFromWalletAddress(common.HexToAddress(paramWalletAddress), common.HexToAddress(paramContractAddress)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get balance").SendD(c) + logo.Errorf("failed to get ERC20 balance of wallet: %v , network: %v, contractAddr: %v , error: %s", paramWalletAddress, network, paramContractAddress, err) + return + } + + balanceInFloat, _ := balance.Float64() + balanceInString := strconv.FormatFloat(balanceInFloat, 'f', -1, 64) + + payload := CheckErc20BalancePayload{ + Balance: balanceInString, + } + httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) +} diff --git a/api/v1/matic/checkbalance/checkbalance_erc20/erc20_test.go b/api/v1/bsc/checkbalance/checkbalance_erc20/erc20_test.go similarity index 53% rename from api/v1/matic/checkbalance/checkbalance_erc20/erc20_test.go rename to api/v1/bsc/checkbalance/checkbalance_erc20/erc20_test.go index e74e097..951944f 100644 --- a/api/v1/matic/checkbalance/checkbalance_erc20/erc20_test.go +++ b/api/v1/bsc/checkbalance/checkbalance_erc20/erc20_test.go @@ -7,12 +7,9 @@ import ( "net/http/httptest" "testing" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) @@ -22,21 +19,13 @@ func Test_CheckBalance(t *testing.T) { appinit.Init() gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "62", - Mnemonic: "long hen advance measure donate child method aspect ceiling saddle turkey cement duck finger armor clarify hamster acid advice caution lazy deal invite remind", - }).Error - if err != nil { - t.Fatal(err) - } t.Run("Fetch user balance for ERC20", func(t *testing.T) { rr := httptest.NewRecorder() c, _ := gin.CreateTestContext(rr) req := CheckErc20BalanceRequest{ - UserId: "62", + WalletAddress: "0x2d7882bedcbfddce29ba99965dd3cdf7fcb10a1e", } body, err := json.Marshal(req) if err != nil { @@ -48,7 +37,7 @@ func Test_CheckBalance(t *testing.T) { t.Fatal(err) } c.Request = httpReq - erc20CheckBalance(c) + erc20CheckBalanceSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) }) } diff --git a/api/v1/matic/checkbalance/checkbalance_erc20/type.go b/api/v1/bsc/checkbalance/checkbalance_erc20/type.go similarity index 53% rename from api/v1/matic/checkbalance/checkbalance_erc20/type.go rename to api/v1/bsc/checkbalance/checkbalance_erc20/type.go index 24d9879..999858f 100644 --- a/api/v1/matic/checkbalance/checkbalance_erc20/type.go +++ b/api/v1/bsc/checkbalance/checkbalance_erc20/type.go @@ -1,8 +1,8 @@ package checkbalance_erc20 type CheckErc20BalanceRequest struct { - UserId string `json:"userId" binding:"required"` - ContractAddr string `json:"contractAddr" binding:"required"` + WalletAddress string `json:"walletAddress" binding:"required"` + ContractAddr string `json:"contractAddr" binding:"required"` } type CheckErc20BalancePayload struct { diff --git a/api/v1/bsc/checkbalance/checkbalance_erc721/erc721.go b/api/v1/bsc/checkbalance/checkbalance_erc721/erc721.go new file mode 100644 index 0000000..2a57775 --- /dev/null +++ b/api/v1/bsc/checkbalance/checkbalance_erc721/erc721.go @@ -0,0 +1,44 @@ +package checkbalance_erc721 + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc721") + { + g.POST("", erc721CheckBalanceWithSalt) + } +} + +func erc721CheckBalanceWithSalt(c *gin.Context) { + var req CheckErc721BalanceWithSalt + err := c.ShouldBindJSON(&req) + if err != nil { + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + network := "bsc" + + var balance *big.Int + balance, err = bsc.GetERC721Balance(req.Mnemonic, common.HexToAddress(req.ContractAddress)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get ERC721 balance").SendD(c) + logo.Errorf("failed to get ERC721 balance of wallet: %v , network: %v, contractAddress: %v , error: %s", req.WalletAddress, network, req.ContractAddress, err) + return + } + + payload := CheckErc721BalancePayload{ + Balance: balance.String(), + } + httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) +} diff --git a/api/v1/bsc/checkbalance/checkbalance_erc721/erc721_test.go b/api/v1/bsc/checkbalance/checkbalance_erc721/erc721_test.go new file mode 100644 index 0000000..82710eb --- /dev/null +++ b/api/v1/bsc/checkbalance/checkbalance_erc721/erc721_test.go @@ -0,0 +1,44 @@ +package checkbalance_erc721 + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_CheckBalance(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + t.Run("Fetch user balance for ERC721", func(t *testing.T) { + rr := httptest.NewRecorder() + c, _ := gin.CreateTestContext(rr) + + req := CheckErc721BalanceWithSalt{ + WalletAddress: "0x975362c36b6842d48d02DBD3A077745Fc1C64175", + ContractAddress: "0x975362c36b6842d48d02DBD3A077745Fc1C64175", + } + body, err := json.Marshal(req) + if err != nil { + t.Fatal(err) + } + + httpReq, err := http.NewRequest("POST", "", bytes.NewBuffer(body)) + if err != nil { + t.Fatal(err) + } + c.Request = httpReq + erc721CheckBalanceWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + }) +} diff --git a/api/v1/matic/checkbalance/checkbalance_erc721/type.go b/api/v1/bsc/checkbalance/checkbalance_erc721/type.go similarity index 52% rename from api/v1/matic/checkbalance/checkbalance_erc721/type.go rename to api/v1/bsc/checkbalance/checkbalance_erc721/type.go index 8743980..c4a3b37 100644 --- a/api/v1/matic/checkbalance/checkbalance_erc721/type.go +++ b/api/v1/bsc/checkbalance/checkbalance_erc721/type.go @@ -5,6 +5,12 @@ type CheckErc721BalanceRequest struct { ContractAddr string `json:"contractAddr" binding:"required"` } +type CheckErc721BalanceWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` +} + type CheckErc721BalancePayload struct { Balance string `json:"balance"` } diff --git a/api/v1/bsc/checkbalance/checkbalance_native/native.go b/api/v1/bsc/checkbalance/checkbalance_native/native.go new file mode 100644 index 0000000..52cd75d --- /dev/null +++ b/api/v1/bsc/checkbalance/checkbalance_native/native.go @@ -0,0 +1,46 @@ +package checkbalance_native + +import ( + "math/big" + "net/http" + "strconv" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/native") + { + g.GET("/:walletAddress", nativeCheckBalanceWithSalt) + } +} + +func nativeCheckBalanceWithSalt(c *gin.Context) { + paramWalletAddress := c.Param("walletAddress") + if len(paramWalletAddress) <= 0 { + httpo.NewErrorResponse(http.StatusBadRequest, "valid wallet address is required").SendD(c) + return + } + network := "bsc" + + var balance *big.Float + balance, err := bsc.GetBalanceInDecimalsFromWalletAddress(paramWalletAddress) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get balance").SendD(c) + logo.Errorf("failed to get balance from wallet of userId: %v and network: %v, error: %s", paramWalletAddress, network, err) + return + } + + balanceInFloat, _ := balance.Float64() + balanceInString := strconv.FormatFloat(balanceInFloat, 'f', -1, 64) + + payload := CheckNativeBalancePayload{ + Balance: balanceInString, + } + httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) +} diff --git a/api/v1/matic/checkbalance/checkbalance_native/native_test.go b/api/v1/bsc/checkbalance/checkbalance_native/native_test.go similarity index 52% rename from api/v1/matic/checkbalance/checkbalance_native/native_test.go rename to api/v1/bsc/checkbalance/checkbalance_native/native_test.go index 86207b7..46be1f3 100644 --- a/api/v1/matic/checkbalance/checkbalance_native/native_test.go +++ b/api/v1/bsc/checkbalance/checkbalance_native/native_test.go @@ -7,12 +7,9 @@ import ( "net/http/httptest" "testing" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) @@ -22,14 +19,7 @@ func Test_CheckBalance(t *testing.T) { appinit.Init() gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "62", - Mnemonic: "long hen advance measure donate child method aspect ceiling saddle turkey cement duck finger armor clarify hamster acid advice caution lazy deal invite remind", - }).Error - if err != nil { - t.Fatal(err) - } + t.Run("Fetch user balance", func(t *testing.T) { rr := httptest.NewRecorder() c, _ := gin.CreateTestContext(rr) @@ -47,7 +37,7 @@ func Test_CheckBalance(t *testing.T) { t.Fatal(err) } c.Request = httpReq - nativeCheckBalance(c) + nativeCheckBalanceWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) }) } diff --git a/api/v1/matic/checkbalance/checkbalance_native/type.go b/api/v1/bsc/checkbalance/checkbalance_native/type.go similarity index 100% rename from api/v1/matic/checkbalance/checkbalance_native/type.go rename to api/v1/bsc/checkbalance/checkbalance_native/type.go diff --git a/api/v1/matic/signMessage/signmessage.go b/api/v1/bsc/signMessage/signmessage.go similarity index 57% rename from api/v1/matic/signMessage/signmessage.go rename to api/v1/bsc/signMessage/signmessage.go index b30b162..881eb04 100644 --- a/api/v1/matic/signMessage/signmessage.go +++ b/api/v1/bsc/signMessage/signmessage.go @@ -1,14 +1,11 @@ package signmessage import ( - "errors" "net/http" "github.com/TheLazarusNetwork/go-helpers/httpo" "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "gorm.io/gorm" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" "github.com/gin-gonic/gin" ) @@ -23,37 +20,22 @@ func ApplyRoutes(r *gin.RouterGroup) { } func signMessage(c *gin.Context) { - var req SignMessageRequest + var req SignMessageRequestWithSalt if err := c.ShouldBindJSON(&req); err != nil { logo.Errorf("invalid request %s", err) httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) return } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s", - req.UserId, err) - return - } - - signature, err := polygon.SignMessage(mnemonic, req.Message) + signature, err := bsc.SignMessage(req.Mnemonic, req.Message) if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to sign").SendD(c) logo.Errorf("failed to sign with walletAddress: %s", err) return } - sendSuccessResponse(c, signature, req.UserId) - + sendSuccessResponse(c, signature, req.WalletAddress) } func sendSuccessResponse(c *gin.Context, signature string, userId string) { diff --git a/api/v1/matic/signMessage/signmessage_test.go b/api/v1/bsc/signMessage/signmessage_test.go similarity index 57% rename from api/v1/matic/signMessage/signmessage_test.go rename to api/v1/bsc/signMessage/signmessage_test.go index c3eb715..18928ac 100644 --- a/api/v1/matic/signMessage/signmessage_test.go +++ b/api/v1/bsc/signMessage/signmessage_test.go @@ -7,12 +7,9 @@ import ( "net/http/httptest" "testing" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) @@ -22,14 +19,6 @@ func Test_SignMessage(t *testing.T) { appinit.Init() gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "60", - Mnemonic: "mobile attend orange oxygen valley fan grape suit tool fancy quality disease potato bean trophy", - }).Error - if err != nil { - t.Fatal(err) - } _ = "0x844507295543d7dcb9a6bf5fa436437eaec309aa2edcfc694a407b8a30e84b464d02934432478d1e201440ec5712c6d7e15e66e1db672cf01d0cf9a1003926881c" @@ -37,9 +26,10 @@ func Test_SignMessage(t *testing.T) { message := "test message to sign" rr := httptest.NewRecorder() - req := SignMessageRequest{ - UserId: "60", - Message: message, + req := SignMessageRequestWithSalt{ + WalletAddress: "", + Mnemonic: "test test test test test test", + Message: message, } d, e := json.Marshal(req) if e != nil { diff --git a/api/v1/bsc/signMessage/types.go b/api/v1/bsc/signMessage/types.go new file mode 100644 index 0000000..aa099f6 --- /dev/null +++ b/api/v1/bsc/signMessage/types.go @@ -0,0 +1,11 @@ +package signmessage + +type SignMessageRequestWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + Message string `json:"message" binding:"required"` +} + +type SignMessagePayload struct { + Signature string `json:"signature"` +} diff --git a/api/v1/matic/transfer/transfer.go b/api/v1/bsc/transfer/transfer.go similarity index 51% rename from api/v1/matic/transfer/transfer.go rename to api/v1/bsc/transfer/transfer.go index ddf48fc..8551f39 100644 --- a/api/v1/matic/transfer/transfer.go +++ b/api/v1/bsc/transfer/transfer.go @@ -1,9 +1,9 @@ package transfer import ( - "github.com/TheLazarusNetwork/superiad/api/v1/matic/transfer/transfer_erc20" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/transfer/transfer_erc721" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/transfer/transfer_native" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/transfer/transfer_erc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/transfer/transfer_erc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/transfer/transfer_native" "github.com/gin-gonic/gin" ) @@ -12,7 +12,6 @@ import ( func ApplyRoutes(r *gin.RouterGroup) { g := r.Group("/transfer") { - transfer_erc20.ApplyRoutes(g) transfer_erc721.ApplyRoutes(g) transfer_native.ApplyRoutes(g) diff --git a/api/v1/bsc/transfer/transfer_erc20/erc20.go b/api/v1/bsc/transfer/transfer_erc20/erc20.go new file mode 100644 index 0000000..6b3a017 --- /dev/null +++ b/api/v1/bsc/transfer/transfer_erc20/erc20.go @@ -0,0 +1,43 @@ +package transfer_erc20 + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc20") + { + + g.POST("", transferWithSalt) + } +} + +func transferWithSalt(c *gin.Context) { + network := "bsc" + var req TransferRequestSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + var hash string + hash, err := bsc.TransferERC20AcceptFloat(req.Mnemonic, common.HexToAddress(req.To), common.HexToAddress(req.ContractAddress), req.Amount) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) + logo.Errorf("failed to tranfer to: %v from wallet: %v , network: %v, contractAddr: %v , error: %s", req.To, req.WalletAddress, network, req.ContractAddress, err) + return + } + payload := TransferPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/bsc/transfer/transfer_erc20/erc20_test.go b/api/v1/bsc/transfer/transfer_erc20/erc20_test.go new file mode 100644 index 0000000..a7dd84b --- /dev/null +++ b/api/v1/bsc/transfer/transfer_erc20/erc20_test.go @@ -0,0 +1,67 @@ +package transfer_erc20 + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_Transfer(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + type network struct { + name string + chainId int64 + erc20Address string + } + networks := []network{ + { + name: "bsc", + chainId: 80001, + erc20Address: "0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e", + }, { + name: "ethereum", + chainId: 1, + erc20Address: "0x514910771af9ca656af840dff83e8264ecf986ca", + }, + } + + t.Run("ERC20 Token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := TransferRequestSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Mnemonic: "test test test test test test", + To: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Amount: 1, + ContractAddress: n.erc20Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http.NewRequest("GET", "", bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + transferWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + +} diff --git a/api/v1/bsc/transfer/transfer_erc20/types.go b/api/v1/bsc/transfer/transfer_erc20/types.go new file mode 100644 index 0000000..72b6a03 --- /dev/null +++ b/api/v1/bsc/transfer/transfer_erc20/types.go @@ -0,0 +1,14 @@ +package transfer_erc20 + +type TransferPayload struct { + TrasactionHash string +} + +type TransferRequestSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + To string `json:"to" binding:"required"` + Amount float64 `json:"amount" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + Salt string `json:"salt" binding:"required"` +} diff --git a/api/v1/bsc/transfer/transfer_erc721/erc721.go b/api/v1/bsc/transfer/transfer_erc721/erc721.go new file mode 100644 index 0000000..3359ade --- /dev/null +++ b/api/v1/bsc/transfer/transfer_erc721/erc721.go @@ -0,0 +1,41 @@ +package transfer_erc721 + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc721") + { + g.POST("", transferWithSalt) + } +} + +func transferWithSalt(c *gin.Context) { + network := "bsc" + var req TransferRequestSalt + err := c.ShouldBindJSON(&req) + if err != nil { + logo.Errorf("Invalid request body: %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + hash, err := bsc.TransferERC721(req.Mnemonic, common.HexToAddress(req.To), common.HexToAddress(req.ContractAddress), *big.NewInt(int64(req.TokenId))) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) + logo.Errorf("failed to tranfer to: %v from wallet: %v , network: %v, contractAddr: %v , error: %s", req.To, req.WalletAddress, network, req.ContractAddress, err) + return + } + + payload := TransferPayload{TrasactionHash: hash} + httpo.NewSuccessResponse(http.StatusOK, "trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/bsc/transfer/transfer_erc721/erc721_test.go b/api/v1/bsc/transfer/transfer_erc721/erc721_test.go new file mode 100644 index 0000000..fd785d0 --- /dev/null +++ b/api/v1/bsc/transfer/transfer_erc721/erc721_test.go @@ -0,0 +1,69 @@ +package transfer_erc721 + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_Transfer(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + type network struct { + name string + chainId int64 + erc20Address string + erc721Address string + } + networks := []network{ + { + name: "bsc", + chainId: 80001, + erc20Address: "0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e", + }, { + name: "ethereum", + chainId: 1, + erc20Address: "0x514910771af9ca656af840dff83e8264ecf986ca", + }, + } + + t.Run("ERC721 Token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := TransferRequest{ + UserId: "60", + To: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Amount: 1, + ContractAddress: n.erc721Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http. + NewRequest("GET", "", + bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + transferWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + +} diff --git a/api/v1/matic/transfer/transfer_erc721/types.go b/api/v1/bsc/transfer/transfer_erc721/types.go similarity index 50% rename from api/v1/matic/transfer/transfer_erc721/types.go rename to api/v1/bsc/transfer/transfer_erc721/types.go index 3ff8ac1..9d586f5 100644 --- a/api/v1/matic/transfer/transfer_erc721/types.go +++ b/api/v1/bsc/transfer/transfer_erc721/types.go @@ -11,3 +11,12 @@ type TransferRequest struct { type TransferPayload struct { TrasactionHash string } + +type TransferRequestSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + To string `json:"to" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} diff --git a/api/v1/bsc/transfer/transfer_native/native.go b/api/v1/bsc/transfer/transfer_native/native.go new file mode 100644 index 0000000..b499181 --- /dev/null +++ b/api/v1/bsc/transfer/transfer_native/native.go @@ -0,0 +1,48 @@ +package transfer_native + +import ( + "math" + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/native") + { + + g.POST("", nativeTransferWithSalt) + } +} + +func nativeTransferWithSalt(c *gin.Context) { + network := "bsc" + var req TransferRequestSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + // Convert float64 to bigInt + var amountInBigInt = big.NewInt(int64(req.Amount * math.Pow(10, 18))) + + var hash string + hash, err := bsc.Transfer(req.Mnemonic, common.HexToAddress(req.To), *amountInBigInt) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) + logo.Errorf("failed to tranfer to: %v from wallet: %v and network: %v, error: %s", req.To, req.WalletAddress, network, err) + return + } + payload := TransferPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/bsc/transfer/transfer_native/native_test.go b/api/v1/bsc/transfer/transfer_native/native_test.go new file mode 100644 index 0000000..89ee9f9 --- /dev/null +++ b/api/v1/bsc/transfer/transfer_native/native_test.go @@ -0,0 +1,48 @@ +package transfer_native + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_Transfer(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + t.Run("Native token", func(t *testing.T) { + rr := httptest.NewRecorder() + + req := TransferRequestSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Mnemonic: "test test test test test test", + To: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Amount: 1, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http.NewRequest("GET", "/", bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + nativeTransferWithSalt(c) + + assert.Equal(t, 200, rr.Result().StatusCode) + + }) + +} diff --git a/api/v1/bsc/transfer/transfer_native/types.go b/api/v1/bsc/transfer/transfer_native/types.go new file mode 100644 index 0000000..5b6fca4 --- /dev/null +++ b/api/v1/bsc/transfer/transfer_native/types.go @@ -0,0 +1,19 @@ +package transfer_native + +type TransferRequest struct { + UserId string `json:"userId" binding:"required"` + To string `json:"to" binding:"required"` + Amount int64 `json:"amount" binding:"required"` +} + +type TransferPayload struct { + TrasactionHash string +} + +type TransferRequestSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + To string `json:"to" binding:"required"` + Amount float64 `json:"amount" binding:"required"` + Salt string `json:"salt" binding:"required"` +} diff --git a/api/v1/bsc/verifySignature/types.go b/api/v1/bsc/verifySignature/types.go new file mode 100644 index 0000000..15784f7 --- /dev/null +++ b/api/v1/bsc/verifySignature/types.go @@ -0,0 +1,8 @@ +package verifysignature + +type VerifyRequest struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + Message string `json:"message" binding:"required"` + Signature string `json:"signature" binding:"required,hexadecimal,len=132"` +} diff --git a/api/v1/matic/verifySignature/verifysigature.go b/api/v1/bsc/verifySignature/verifysigature.go similarity index 60% rename from api/v1/matic/verifySignature/verifysigature.go rename to api/v1/bsc/verifySignature/verifysigature.go index 8bf4356..9b3f769 100644 --- a/api/v1/matic/verifySignature/verifysigature.go +++ b/api/v1/bsc/verifySignature/verifysigature.go @@ -1,15 +1,12 @@ package verifysignature import ( - "errors" "fmt" "net/http" "github.com/TheLazarusNetwork/go-helpers/httpo" "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "gorm.io/gorm" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" "github.com/gin-gonic/gin" ) @@ -23,31 +20,19 @@ func ApplyRoutes(r *gin.RouterGroup) { } func verifySignature(c *gin.Context) { - network := "matic" + network := "bsc" var req VerifyRequest if err := c.ShouldBindJSON(&req); err != nil { err := fmt.Errorf("body is invalid: %w", err) httpo.NewErrorResponse(http.StatusBadRequest, err.Error()).SendD(c) return } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - return - } - - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s", - req.UserId, err) - return - } - res, err := polygon.VerifySignature(mnemonic, req.Message, req.Signature) + res, err := bsc.VerifySignature(req.Mnemonic, req.Message, req.Signature) if err != nil { httpo.NewErrorResponse(http.StatusInternalServerError, "failed to verify signature").SendD(c) logo.Errorf("failed to verify signature from wallet of userId: %v and network: %v, error: %s", - req.UserId, network, err) + req.WalletAddress, network, err) return } diff --git a/api/v1/bsc/virtuacoinnft/burn/burn.go b/api/v1/bsc/virtuacoinnft/burn/burn.go new file mode 100644 index 0000000..2d6808b --- /dev/null +++ b/api/v1/bsc/virtuacoinnft/burn/burn.go @@ -0,0 +1,46 @@ +package burn + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + virtuacoin "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc/virtuacoinnft" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/burn") + { + g.POST("", burnWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := BurnPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func burnWithSalt(c *gin.Context) { + network := "bsc" + var req BurnWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("Invalid request body:%s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + + hash, err := virtuacoin.Burn(req.Mnemonic, common.HexToAddress(req.ContractAddress), *big.NewInt(req.TokenId)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to burn").SendD(c) + logo.Errorf("failed to burn tokenId: %v from wallet of: %v, network: %v, contractAddr: %v, error: %s", req.TokenId, req.WalletAddress, network, req.ContractAddress, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) +} diff --git a/api/v1/bsc/virtuacoinnft/burn/types.go b/api/v1/bsc/virtuacoinnft/burn/types.go new file mode 100644 index 0000000..ecb8f5d --- /dev/null +++ b/api/v1/bsc/virtuacoinnft/burn/types.go @@ -0,0 +1,13 @@ +package burn + +type BurnWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} + +type BurnPayload struct { + TrasactionHash string +} diff --git a/api/v1/bsc/virtuacoinnft/delegateassetcreation/delegateassetcreation.go b/api/v1/bsc/virtuacoinnft/delegateassetcreation/delegateassetcreation.go new file mode 100644 index 0000000..f0e37f1 --- /dev/null +++ b/api/v1/bsc/virtuacoinnft/delegateassetcreation/delegateassetcreation.go @@ -0,0 +1,44 @@ +package delegateassetcreation + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + virtuacoin "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc/virtuacoinnft" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/delegateassetcreation") + { + g.POST("", delegateAssetCreation) + } +} + +func delegateAssetCreation(c *gin.Context) { + network := "bsc" + var req DelegateAssetCreationRequest + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + erc721ContractAddr := common.HexToAddress(req.ContractAddress) + var hash string + hash, err := virtuacoin.DelegateAssetCreation(req.WalletAddress, erc721ContractAddr, req.MetadataURI) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to delegateAssetCreation").SendD(c) + logo.Errorf("failed to delegateAssetCreation of erc721 to wallet Address: %v , network: %v, contractAddr: %v, error: %s", req.WalletAddress, network, req.ContractAddress, err) + return + } + payload := DelegateErc721Payload{ + TrasactionHash: hash, + } + + httpo.NewSuccessResponse(200, "delegateAssetCreation trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/bsc/virtuacoinnft/delegateassetcreation/types.go b/api/v1/bsc/virtuacoinnft/delegateassetcreation/types.go new file mode 100644 index 0000000..17ef1a8 --- /dev/null +++ b/api/v1/bsc/virtuacoinnft/delegateassetcreation/types.go @@ -0,0 +1,11 @@ +package delegateassetcreation + +type DelegateAssetCreationRequest struct { + WalletAddress string `json:"walletAddress" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + MetadataURI string `json:"metadataURI" binding:"required,min=1"` +} + +type DelegateErc721Payload struct { + TrasactionHash string +} diff --git a/api/v1/bsc/virtuacoinnft/grantrole/grantrole.go b/api/v1/bsc/virtuacoinnft/grantrole/grantrole.go new file mode 100644 index 0000000..2dc0a4d --- /dev/null +++ b/api/v1/bsc/virtuacoinnft/grantrole/grantrole.go @@ -0,0 +1,45 @@ +package grantrole + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + virtuacoin "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc/virtuacoinnft" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/grantrole") + { + g.POST("", grantRole) + } +} + +func grantRole(c *gin.Context) { + network := "bsc" + var req GrantRoleRequest + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + erc721ContractAddress := common.HexToAddress(req.ContractAddress) + + var hash string + hash, err := virtuacoin.GrantRole(req.RoleId, req.WalletAddress, erc721ContractAddress) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to grantRole").SendD(c) + logo.Errorf("failed to grantRole of %v in VirtuaCoinNFT to wallet Address: %v , network: %v, contractAddr: %v, error: %s", req.RoleId, req.WalletAddress, network, req.ContractAddress, err) + return + } + payload := GrantRolePayload{ + TrasactionHash: hash, + } + + httpo.NewSuccessResponse(200, "grantRole trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/bsc/virtuacoinnft/grantrole/types.go b/api/v1/bsc/virtuacoinnft/grantrole/types.go new file mode 100644 index 0000000..ce8a517 --- /dev/null +++ b/api/v1/bsc/virtuacoinnft/grantrole/types.go @@ -0,0 +1,11 @@ +package grantrole + +type GrantRoleRequest struct { + RoleId string `json:"roleId" binding:"required"` + WalletAddress string `json:"walletAddress" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` +} + +type GrantRolePayload struct { + TrasactionHash string +} diff --git a/api/v1/bsc/virtuacoinnft/virtuacoinnft.go b/api/v1/bsc/virtuacoinnft/virtuacoinnft.go new file mode 100644 index 0000000..2edbc96 --- /dev/null +++ b/api/v1/bsc/virtuacoinnft/virtuacoinnft.go @@ -0,0 +1,18 @@ +package virtuacoinnft + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/virtuacoinnft/burn" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/virtuacoinnft/delegateassetcreation" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc/virtuacoinnft/grantrole" + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/virtuacoinnft") + { + delegateassetcreation.ApplyRoutes(g) + grantrole.ApplyRoutes(g) + burn.ApplyRoutes(g) + } +} diff --git a/api/v1/ethereum/checkbalance/checkbalance.go b/api/v1/ethereum/checkbalance/checkbalance.go new file mode 100644 index 0000000..4c0398a --- /dev/null +++ b/api/v1/ethereum/checkbalance/checkbalance.go @@ -0,0 +1,15 @@ +package checkbalance + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/ethereum/checkbalance/checkbalance_erc20" + + "github.com/gin-gonic/gin" +) + +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/checkbalance") + { + checkbalance_erc20.ApplyRoutes(g) + + } +} diff --git a/api/v1/ethereum/checkbalance/checkbalance_erc20/erc20.go b/api/v1/ethereum/checkbalance/checkbalance_erc20/erc20.go new file mode 100644 index 0000000..9dd6f9d --- /dev/null +++ b/api/v1/ethereum/checkbalance/checkbalance_erc20/erc20.go @@ -0,0 +1,45 @@ +package checkbalance_erc20 + +import ( + "net/http" + "strconv" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/ethereum" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc20") + { + g.GET("/:contractAddress/:walletAddress", erc20CheckBalanceSalt) + } +} + +func erc20CheckBalanceSalt(c *gin.Context) { + paramContractAddress := c.Param("contractAddress") + paramWalletAddress := c.Param("walletAddress") + if len(paramWalletAddress) <= 0 { + httpo.NewErrorResponse(http.StatusBadRequest, "valid wallet address is required").SendD(c) + return + } + network := "ethereum" + + balance, err := ethereum.GetERC20BalanceInDecimalsFromWalletAddress(common.HexToAddress(paramWalletAddress), common.HexToAddress(paramContractAddress)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get balance").SendD(c) + logo.Errorf("failed to get ERC20 balance of wallet: %v , network: %v, contractAddr: %v , error: %s", paramWalletAddress, network, paramContractAddress, err) + return + } + + balanceInFloat, _ := balance.Float64() + balanceInString := strconv.FormatFloat(balanceInFloat, 'f', -1, 64) + + payload := CheckErc20BalancePayload{ + Balance: balanceInString, + } + httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) +} diff --git a/api/v1/ethereum/checkbalance/checkbalance_erc20/erc20_test.go b/api/v1/ethereum/checkbalance/checkbalance_erc20/erc20_test.go new file mode 100644 index 0000000..951944f --- /dev/null +++ b/api/v1/ethereum/checkbalance/checkbalance_erc20/erc20_test.go @@ -0,0 +1,43 @@ +package checkbalance_erc20 + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_CheckBalance(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + t.Run("Fetch user balance for ERC20", func(t *testing.T) { + rr := httptest.NewRecorder() + c, _ := gin.CreateTestContext(rr) + + req := CheckErc20BalanceRequest{ + WalletAddress: "0x2d7882bedcbfddce29ba99965dd3cdf7fcb10a1e", + } + body, err := json.Marshal(req) + if err != nil { + t.Fatal(err) + } + + httpReq, err := http.NewRequest("POST", "/?erc20address=0x2d7882bedcbfddce29ba99965dd3cdf7fcb10a1e", bytes.NewBuffer(body)) + if err != nil { + t.Fatal(err) + } + c.Request = httpReq + erc20CheckBalanceSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + }) +} diff --git a/api/v1/ethereum/checkbalance/checkbalance_erc20/type.go b/api/v1/ethereum/checkbalance/checkbalance_erc20/type.go new file mode 100644 index 0000000..999858f --- /dev/null +++ b/api/v1/ethereum/checkbalance/checkbalance_erc20/type.go @@ -0,0 +1,10 @@ +package checkbalance_erc20 + +type CheckErc20BalanceRequest struct { + WalletAddress string `json:"walletAddress" binding:"required"` + ContractAddr string `json:"contractAddr" binding:"required"` +} + +type CheckErc20BalancePayload struct { + Balance string `json:"balance"` +} diff --git a/api/v1/ethereum/ethereum.go b/api/v1/ethereum/ethereum.go new file mode 100644 index 0000000..70631ff --- /dev/null +++ b/api/v1/ethereum/ethereum.go @@ -0,0 +1,19 @@ +package ethereum + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/ethereum/checkbalance" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/ethereum/transfer" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes Use the given Routes +func ApplyRoutes(r *gin.RouterGroup) { + v1 := r.Group("/ethereum") + { + checkbalance.ApplyRoutes(v1) + + transfer.ApplyRoutes(v1) + + } +} diff --git a/api/v1/ethereum/transfer/transfer.go b/api/v1/ethereum/transfer/transfer.go new file mode 100644 index 0000000..941ea91 --- /dev/null +++ b/api/v1/ethereum/transfer/transfer.go @@ -0,0 +1,15 @@ +package transfer + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/ethereum/transfer/transfer_erc20" + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/transfer") + { + transfer_erc20.ApplyRoutes(g) + + } +} diff --git a/api/v1/ethereum/transfer/transfer_erc20/erc20.go b/api/v1/ethereum/transfer/transfer_erc20/erc20.go new file mode 100644 index 0000000..ee23552 --- /dev/null +++ b/api/v1/ethereum/transfer/transfer_erc20/erc20.go @@ -0,0 +1,48 @@ +package transfer_erc20 + +import ( + "math/big" + "net/http" + "strconv" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/ethereum" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc20") + { + + g.POST("", transferWithSalt) + } +} + +func transferWithSalt(c *gin.Context) { + network := "ethereum" + var req TransferRequestSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + var hash string + amount := new(big.Int) + amountStr := strconv.FormatFloat(req.Amount, 'f', -1, 64) + amount.SetString(amountStr, 10) + + hash, err := ethereum.TransferERC20(req.Mnemonic, common.HexToAddress(req.To), common.HexToAddress(req.ContractAddress), amount) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to transfer").SendD(c) + logo.Errorf("failed to transfer to: %v from wallet: %v , network: %v, contractAddr: %v , error: %s", req.To, req.WalletAddress, network, req.ContractAddress, err) + return + } + payload := TransferPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/matic/transfer/transfer_erc20/erc20_test.go b/api/v1/ethereum/transfer/transfer_erc20/erc20_test.go similarity index 64% rename from api/v1/matic/transfer/transfer_erc20/erc20_test.go rename to api/v1/ethereum/transfer/transfer_erc20/erc20_test.go index 5064155..39f8ddb 100644 --- a/api/v1/matic/transfer/transfer_erc20/erc20_test.go +++ b/api/v1/ethereum/transfer/transfer_erc20/erc20_test.go @@ -7,12 +7,9 @@ import ( "net/http/httptest" "testing" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) @@ -22,14 +19,6 @@ func Test_Transfer(t *testing.T) { appinit.Init() gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "60", - Mnemonic: "mobile attend orange oxygen valley fan grape suit tool fancy quality disease potato bean trophy", - }).Error - if err != nil { - t.Fatal(err) - } type network struct { name string @@ -52,8 +41,9 @@ func Test_Transfer(t *testing.T) { for _, n := range networks { rr := httptest.NewRecorder() - req := TransferRequest{ - UserId: "60", + req := TransferRequestSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Mnemonic: "test test test test test test", To: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", Amount: 1, ContractAddress: n.erc20Address, @@ -68,7 +58,7 @@ func Test_Transfer(t *testing.T) { t.Fatal(e) } c.Request = httpReq - transfer(c) + transferWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } diff --git a/api/v1/ethereum/transfer/transfer_erc20/types.go b/api/v1/ethereum/transfer/transfer_erc20/types.go new file mode 100644 index 0000000..72b6a03 --- /dev/null +++ b/api/v1/ethereum/transfer/transfer_erc20/types.go @@ -0,0 +1,14 @@ +package transfer_erc20 + +type TransferPayload struct { + TrasactionHash string +} + +type TransferRequestSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + To string `json:"to" binding:"required"` + Amount float64 `json:"amount" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + Salt string `json:"salt" binding:"required"` +} diff --git a/api/v1/matic/approve/approve.go b/api/v1/matic/approve/approve.go deleted file mode 100644 index 21d42b5..0000000 --- a/api/v1/matic/approve/approve.go +++ /dev/null @@ -1,69 +0,0 @@ -package approve - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/approve") - { - - g.POST("", approve) - } -} - -func approve(c *gin.Context) { - network := "matic" - var req ApproveRequest - if err := c.ShouldBindJSON(&req); err != nil { - logo.Errorf("invalid request %s", err) - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - return - } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s", - req.UserId, err) - - return - } - - var hash string - - hash, err = polygon.ApproveERC721(mnemonic, common.HexToAddress(req.ToAddress), common.HexToAddress(req.ContractAddress), *big.NewInt(req.TokenId)) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve").SendD(c) - logo.Errorf("failed to approve to: %v from wallet of userId: %v, network: %v, contractAddr: %v, tokenId: %v, error: %s", req.ToAddress, - req.UserId, network, req.ContractAddress, req.TokenId, err) - return - } - - sendSuccessResponse(c, hash, req.UserId) -} - -func sendSuccessResponse(c *gin.Context, hash string, userId string) { - payload := TransferPayload{ - TrasactionHash: hash, - } - if err := user.AddTrasactionHash(userId, hash); err != nil { - logo.Errorf("failed to add transaction hash: %v to user id: %v, error: %s", hash, userId, err) - } - httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) -} diff --git a/api/v1/matic/approve/types.go b/api/v1/matic/approve/types.go deleted file mode 100644 index 3865774..0000000 --- a/api/v1/matic/approve/types.go +++ /dev/null @@ -1,12 +0,0 @@ -package approve - -type ApproveRequest struct { - UserId string `json:"userId" binding:"required"` - ToAddress string `json:"toAddress" binding:"required"` - ContractAddress string `json:"contractAddress" binding:"required"` - TokenId int64 `json:"tokenId" binding:"required"` -} - -type TransferPayload struct { - TrasactionHash string -} diff --git a/api/v1/matic/approveAll/approveall.go b/api/v1/matic/approveAll/approveall.go deleted file mode 100644 index 8131fb5..0000000 --- a/api/v1/matic/approveAll/approveall.go +++ /dev/null @@ -1,67 +0,0 @@ -package approveall - -import ( - "errors" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/approve-all") - { - g.POST("", approveAll) - } -} - -func approveAll(c *gin.Context) { - network := "matic" - var req ApproveAllRequest - if err := c.ShouldBindJSON(&req); err != nil { - logo.Errorf("invalid request %s", err) - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - return - } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s", - req.UserId, err) - return - } - - var hash string - - hash, err = polygon.SetAprovalForAllErc721(mnemonic, common.HexToAddress(req.OperatorAddress), common.HexToAddress(req.ContractAddress), req.Approved) - if err != nil { - - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve all").SendD(c) - logo.Errorf("failed to approve all to operator: %v from wallet of userId: %v, network: %v, contractAddr: %v, error: %s", req.OperatorAddress, - req.UserId, network, req.ContractAddress, err) - return - } - - sendSuccessResponse(c, hash, req.UserId) -} - -func sendSuccessResponse(c *gin.Context, hash string, userId string) { - payload := TransferPayload{ - TrasactionHash: hash, - } - if err := user.AddTrasactionHash(userId, hash); err != nil { - logo.Errorf("failed to add transaction hash: %v to user id: %v, error: %s", hash, userId, err) - } - httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) -} diff --git a/api/v1/matic/checkbalance/checkbalance_erc20/erc20.go b/api/v1/matic/checkbalance/checkbalance_erc20/erc20.go deleted file mode 100644 index 6ba5b7f..0000000 --- a/api/v1/matic/checkbalance/checkbalance_erc20/erc20.go +++ /dev/null @@ -1,60 +0,0 @@ -package checkbalance_erc20 - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/erc20") - { - - g.POST("", erc20CheckBalance) - } -} - -func erc20CheckBalance(c *gin.Context) { - var req CheckErc20BalanceRequest - err := c.ShouldBindJSON(&req) - if err != nil { - httpo.NewErrorResponse(http.StatusBadRequest, "body is not valid").Send(c, http.StatusBadRequest) - return - } - network := "matic" - - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user with id %v, err %s", req.UserId, err) - return - } - var balance *big.Int - - balance, err = polygon.GetERC20Balance(mnemonic, common.HexToAddress(req.ContractAddr)) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get balance").SendD(c) - logo.Errorf("failed to get ERC20 balance of wallet of userId: %v , network: %v, contractAddr: %v , error: %s", req.UserId, - network, req.ContractAddr, err) - return - } - - payload := CheckErc20BalancePayload{ - Balance: balance.String(), - } - httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) -} diff --git a/api/v1/matic/checkbalance/checkbalance_erc721/erc721.go b/api/v1/matic/checkbalance/checkbalance_erc721/erc721.go deleted file mode 100644 index 0e38c2c..0000000 --- a/api/v1/matic/checkbalance/checkbalance_erc721/erc721.go +++ /dev/null @@ -1,62 +0,0 @@ -package checkbalance_erc721 - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/erc721") - { - - g.POST("", erc721CheckBalance) - } -} - -func erc721CheckBalance(c *gin.Context) { - var req CheckErc721BalanceRequest - err := c.ShouldBindJSON(&req) - if err != nil { - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - - return - } - network := "matic" - - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user with id %v, err %s", req.UserId, err) - return - } - var balance *big.Int - - balance, err = polygon.GetERC721Balance(mnemonic, common.HexToAddress(req.ContractAddr)) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get ERC721 balance").SendD(c) - logo.Errorf("failed to get ERC721 balance of wallet of userId: %v , network: %v, contractAddr: %v , error: %s", req.UserId, - network, req.ContractAddr, err) - return - } - - payload := CheckErc721BalancePayload{ - Balance: balance.String(), - } - httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) -} diff --git a/api/v1/matic/checkbalance/checkbalance_erc721/erc721_test.go b/api/v1/matic/checkbalance/checkbalance_erc721/erc721_test.go deleted file mode 100644 index 5457f6e..0000000 --- a/api/v1/matic/checkbalance/checkbalance_erc721/erc721_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package checkbalance_erc721 - -import ( - "bytes" - "encoding/json" - "net/http" - "net/http/httptest" - "testing" - - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" - "github.com/gin-gonic/gin" - "github.com/stretchr/testify/assert" -) - -func Test_CheckBalance(t *testing.T) { - envconfig.InitEnvVars() - - appinit.Init() - gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "62", - Mnemonic: "long hen advance measure donate child method aspect ceiling saddle turkey cement duck finger armor clarify hamster acid advice caution lazy deal invite remind", - }).Error - if err != nil { - t.Fatal(err) - } - t.Run("Fetch user balance for ERC721", func(t *testing.T) { - rr := httptest.NewRecorder() - c, _ := gin.CreateTestContext(rr) - - req := CheckErc721BalanceRequest{ - UserId: "62", - ContractAddr: "0x975362c36b6842d48d02DBD3A077745Fc1C64175", - } - body, err := json.Marshal(req) - if err != nil { - t.Fatal(err) - } - - httpReq, err := http.NewRequest("POST", "", bytes.NewBuffer(body)) - if err != nil { - t.Fatal(err) - } - c.Request = httpReq - erc721CheckBalance(c) - assert.Equal(t, 200, rr.Result().StatusCode) - }) -} diff --git a/api/v1/matic/checkbalance/checkbalance_native/native.go b/api/v1/matic/checkbalance/checkbalance_native/native.go deleted file mode 100644 index 7233ab6..0000000 --- a/api/v1/matic/checkbalance/checkbalance_native/native.go +++ /dev/null @@ -1,61 +0,0 @@ -package checkbalance_native - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/native") - { - - g.POST("", nativeCheckBalance) - } -} - -func nativeCheckBalance(c *gin.Context) { - var req CheckNativeBalanceRequest - err := c.ShouldBindJSON(&req) - if err != nil { - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - - return - } - network := "matic" - - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user with id %v, err %s", req.UserId, err) - return - } - var balance *big.Int - - balance, err = polygon.GetBalance(mnemonic) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get balance").SendD(c) - logo.Errorf("failed to get balance from wallet of userId: %v and network: %v, error: %s", - req.UserId, network, err) - return - } - - payload := CheckNativeBalancePayload{ - Balance: balance.String(), - } - httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) -} diff --git a/api/v1/matic/fetchwallet/fetchwallet.go b/api/v1/matic/fetchwallet/fetchwallet.go deleted file mode 100644 index f530f88..0000000 --- a/api/v1/matic/fetchwallet/fetchwallet.go +++ /dev/null @@ -1,55 +0,0 @@ -package fetchwallet - -import ( - "errors" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/fetchwallet/:userId") - { - - g.GET("", fetchwallet) - } -} - -func fetchwallet(c *gin.Context) { - paramUserId := c.Param("userId") - if len(paramUserId) <= 0 { - httpo.NewErrorResponse(http.StatusBadRequest, "userId is required in /fetchwallet/:userId").SendD(c) - return - } - - mnemonic, err := user.GetMnemonic(paramUserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic, error: %s", err) - return - } - - walletAddr, err := polygon.GetWalletAddres(mnemonic) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get wallet address").SendD(c) - logo.Errorf("failed to get wallet address for userId: %v", paramUserId) - return - } - - payload := FetchWalletPayload{ - WalletAddress: walletAddr, - } - httpo.NewSuccessResponse(200, "wallet address fetched", payload).SendD(c) - -} diff --git a/api/v1/matic/fetchwallet/fetchwallet_test.go b/api/v1/matic/fetchwallet/fetchwallet_test.go deleted file mode 100644 index f156c89..0000000 --- a/api/v1/matic/fetchwallet/fetchwallet_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package fetchwallet - -import ( - "net/http/httptest" - "testing" - - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" - "github.com/gin-gonic/gin" - "github.com/stretchr/testify/assert" -) - -func Test_FetchWallet(t *testing.T) { - envconfig.InitEnvVars() - - appinit.Init() - gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "67", - Mnemonic: "canyon butter soup wet lemon rent mix brick wood wolf indicate fuel coral police beef goose rely frog toss roast beauty index tiger sample", - }).Error - if err != nil { - t.Fatal(err) - } - - rr := httptest.NewRecorder() - - c, _ := gin.CreateTestContext(rr) - fetchwallet(c) - assert.Contains(t, rr.Body.String(), "0x2c08ABf0d1e7A89419bd8E44E946a2a2FA769Dd3") - assert.Equal(t, 200, rr.Result().StatusCode) -} diff --git a/api/v1/matic/fetchwallet/types.go b/api/v1/matic/fetchwallet/types.go deleted file mode 100644 index 73d8c28..0000000 --- a/api/v1/matic/fetchwallet/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package fetchwallet - -type FetchWalletPayload struct { - WalletAddress string `json:"walletAddress"` -} diff --git a/api/v1/matic/isowner/isowner.go b/api/v1/matic/isowner/isowner.go deleted file mode 100644 index 24e0a5f..0000000 --- a/api/v1/matic/isowner/isowner.go +++ /dev/null @@ -1,59 +0,0 @@ -package isowner - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/isowner") - { - - g.POST("", isowner) - } -} - -func isowner(c *gin.Context) { - var req IsOwnerRequest - err := c.ShouldBindJSON(&req) - if err != nil { - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - - return - } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user with id %v, err %s", req.UserId, err) - return - } - - isOwner, err := polygon.ERC721IsOwner(mnemonic, common.HexToAddress(req.ContractAddress), big.NewInt(req.TokenId)) - - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to call ERC721IsOwner").SendD(c) - logo.Errorf("failed to call ERC721IsOwner for user with id %v,erc721Address %v,tokenId %v, err %s", req.UserId, req.ContractAddress, req.TokenId, err) - return - } - payload := IsOwnerPayload{ - IsOwner: isOwner, - } - httpo.NewSuccessResponse(200, "Result success", payload).SendD(c) - -} diff --git a/api/v1/matic/isowner/isowner_test.go b/api/v1/matic/isowner/isowner_test.go deleted file mode 100644 index bee1587..0000000 --- a/api/v1/matic/isowner/isowner_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package isowner - -import ( - "bytes" - "encoding/json" - "net/http" - "net/http/httptest" - "testing" - - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" - "github.com/gin-gonic/gin" - "github.com/stretchr/testify/assert" -) - -func Test_IsOwner(t *testing.T) { - envconfig.InitEnvVars() - - appinit.Init() - gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "62", - Mnemonic: "long hen advance measure donate child method aspect ceiling saddle turkey cement duck finger armor clarify hamster acid advice caution lazy deal invite remind", - }).Error - if err != nil { - t.Fatal(err) - } - - t.Run("Should return true for owned token", func(t *testing.T) { - rr := httptest.NewRecorder() - c, _ := gin.CreateTestContext(rr) - - req := IsOwnerRequest{ - UserId: "62", - TokenId: 27, - } - body, err := json.Marshal(req) - if err != nil { - t.Fatal(err) - } - - httpReq, err := http.NewRequest("POST", "/?erc721Address=0x975362c36b6842d48d02DBD3A077745Fc1C64175", bytes.NewBuffer(body)) - if err != nil { - t.Fatal(err) - } - c.Request = httpReq - isowner(c) - assert.Equal(t, 200, rr.Result().StatusCode) - assert.Contains(t, rr.Body.String(), "true") - }) - - t.Run("Should return false for token which is not owned", func(t *testing.T) { - rr := httptest.NewRecorder() - c, _ := gin.CreateTestContext(rr) - - req := IsOwnerRequest{ - UserId: "62", - TokenId: 4, - } - body, err := json.Marshal(req) - if err != nil { - t.Fatal(err) - } - - httpReq, err := http.NewRequest("POST", "/?erc721Address=0x975362c36b6842d48d02DBD3A077745Fc1C64175", bytes.NewBuffer(body)) - if err != nil { - t.Fatal(err) - } - c.Request = httpReq - isowner(c) - assert.Equal(t, 200, rr.Result().StatusCode) - assert.Contains(t, rr.Body.String(), "false") - }) - -} diff --git a/api/v1/matic/isowner/types.go b/api/v1/matic/isowner/types.go deleted file mode 100644 index 3c2471a..0000000 --- a/api/v1/matic/isowner/types.go +++ /dev/null @@ -1,11 +0,0 @@ -package isowner - -type IsOwnerRequest struct { - UserId string `json:"userId" binding:"required"` - TokenId int64 `json:"tokenId" binding:"required"` - ContractAddress string `json:"contractAddress" binding:"required"` -} - -type IsOwnerPayload struct { - IsOwner bool `json:"isOwner" binding:"required"` -} diff --git a/api/v1/matic/matic.go b/api/v1/matic/matic.go deleted file mode 100644 index 43550a3..0000000 --- a/api/v1/matic/matic.go +++ /dev/null @@ -1,32 +0,0 @@ -package matic - -import ( - "github.com/TheLazarusNetwork/superiad/api/middleware/onlyunlockedmiddleware" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/approve" - approveall "github.com/TheLazarusNetwork/superiad/api/v1/matic/approveAll" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/checkbalance" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/fetchwallet" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/isowner" - signmessage "github.com/TheLazarusNetwork/superiad/api/v1/matic/signMessage" - "github.com/TheLazarusNetwork/superiad/api/v1/matic/transfer" - verifysignature "github.com/TheLazarusNetwork/superiad/api/v1/matic/verifySignature" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes Use the given Routes -func ApplyRoutes(r *gin.RouterGroup) { - v1 := r.Group("/matic") - { - checkbalance.ApplyRoutes(v1) - fetchwallet.ApplyRoutes(v1) - isowner.ApplyRoutes(v1) - verifysignature.ApplyRoutes(v1) - - v1.Use(onlyunlockedmiddleware.OnlyUnlocked()) - signmessage.ApplyRoutes(v1) - transfer.ApplyRoutes(v1) - approve.ApplyRoutes(v1) - approveall.ApplyRoutes(v1) - } -} diff --git a/api/v1/matic/signMessage/types.go b/api/v1/matic/signMessage/types.go deleted file mode 100644 index 478a1da..0000000 --- a/api/v1/matic/signMessage/types.go +++ /dev/null @@ -1,10 +0,0 @@ -package signmessage - -type SignMessageRequest struct { - UserId string `json:"userId" binding:"required"` - Message string `json:"message" binding:"required"` -} - -type SignMessagePayload struct { - Signature string `json:"signature"` -} diff --git a/api/v1/matic/transfer/transfer_erc20/erc20.go b/api/v1/matic/transfer/transfer_erc20/erc20.go deleted file mode 100644 index d21cfb0..0000000 --- a/api/v1/matic/transfer/transfer_erc20/erc20.go +++ /dev/null @@ -1,68 +0,0 @@ -package transfer_erc20 - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/erc20") - { - - g.POST("", transfer) - } -} - -func transfer(c *gin.Context) { - network := "matic" - var req TransferRequest - if err := c.ShouldBindJSON(&req); err != nil { - logo.Errorf("invalid request %s", err) - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - return - } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - - return - } - - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s", - req.UserId, err) - return - } - - var hash string - hash, err = polygon.TransferERC20(mnemonic, common.HexToAddress(req.To), common.HexToAddress(req.ContractAddress), *big.NewInt(req.Amount)) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) - logo.Errorf("failed to tranfer to: %v from wallet of userId: %v , network: %v, contractAddr: %v , error: %s", req.To, - req.UserId, network, req.ContractAddress, err) - return - } - sendSuccessResponse(c, hash, req.UserId) -} - -func sendSuccessResponse(c *gin.Context, hash string, userId string) { - payload := TransferPayload{ - TrasactionHash: hash, - } - if err := user.AddTrasactionHash(userId, hash); err != nil { - logo.Errorf("failed to add transaction hash: %v to user id: %v, error: %s", hash, userId, err) - } - httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) -} diff --git a/api/v1/matic/transfer/transfer_erc20/types.go b/api/v1/matic/transfer/transfer_erc20/types.go deleted file mode 100644 index eaaa689..0000000 --- a/api/v1/matic/transfer/transfer_erc20/types.go +++ /dev/null @@ -1,12 +0,0 @@ -package transfer_erc20 - -type TransferRequest struct { - UserId string `json:"userId" binding:"required"` - To string `json:"to" binding:"required"` - Amount int64 `json:"amount" binding:"required"` - ContractAddress string `json:"contractAddress" binding:"required"` -} - -type TransferPayload struct { - TrasactionHash string -} diff --git a/api/v1/matic/transfer/transfer_erc721/erc721.go b/api/v1/matic/transfer/transfer_erc721/erc721.go deleted file mode 100644 index a48cea3..0000000 --- a/api/v1/matic/transfer/transfer_erc721/erc721.go +++ /dev/null @@ -1,68 +0,0 @@ -package transfer_erc721 - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/erc721") - { - - g.POST("", transfer) - } -} - -func transfer(c *gin.Context) { - network := "matic" - var req TransferRequest - if err := c.ShouldBindJSON(&req); err != nil { - logo.Errorf("invalid request %s", err) - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - return - } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - - return - } - - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s", - req.UserId, err) - return - } - - var hash string - hash, err = polygon.TransferERC721(mnemonic, common.HexToAddress(req.To), common.HexToAddress(req.ContractAddress), *big.NewInt(int64(req.TokenId))) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) - logo.Errorf("failed to tranfer to: %v from wallet of userId: %v , network: %v, contractAddr: %v,tokenId %v, error: %s", req.To, - req.UserId, network, req.ContractAddress, req.TokenId, err) - return - } - sendSuccessResponse(c, hash, req.UserId) -} - -func sendSuccessResponse(c *gin.Context, hash string, userId string) { - payload := TransferPayload{ - TrasactionHash: hash, - } - if err := user.AddTrasactionHash(userId, hash); err != nil { - logo.Errorf("failed to add transaction hash: %v to user id: %v, error: %s", hash, userId, err) - } - httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) -} diff --git a/api/v1/matic/transfer/transfer_native/native.go b/api/v1/matic/transfer/transfer_native/native.go deleted file mode 100644 index 4a664e4..0000000 --- a/api/v1/matic/transfer/transfer_native/native.go +++ /dev/null @@ -1,68 +0,0 @@ -package transfer_native - -import ( - "errors" - "math/big" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/network/polygon" - "github.com/ethereum/go-ethereum/common" - "gorm.io/gorm" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/native") - { - - g.POST("", nativeTransfer) - } -} - -func nativeTransfer(c *gin.Context) { - network := "matic" - var req TransferRequest - if err := c.ShouldBindJSON(&req); err != nil { - logo.Errorf("invalid request %s", err) - httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) - return - } - mnemonic, err := user.GetMnemonic(req.UserId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - - return - } - - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c) - logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s", - req.UserId, err) - return - } - - var hash string - hash, err = polygon.Transfer(mnemonic, common.HexToAddress(req.To), *big.NewInt(req.Amount)) - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) - logo.Errorf("failed to tranfer to: %v from wallet of userId: %v and network: %v, error: %s", req.To, - req.UserId, network, err) - return - } - sendSuccessResponse(c, hash, req.UserId) -} - -func sendSuccessResponse(c *gin.Context, hash string, userId string) { - payload := TransferPayload{ - TrasactionHash: hash, - } - if err := user.AddTrasactionHash(userId, hash); err != nil { - logo.Errorf("failed to add transaction hash: %v to user id: %v, error: %s", hash, userId, err) - } - httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) -} diff --git a/api/v1/matic/transfer/transfer_native/native_test.go b/api/v1/matic/transfer/transfer_native/native_test.go deleted file mode 100644 index b17a37e..0000000 --- a/api/v1/matic/transfer/transfer_native/native_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package transfer_native - -import ( - "bytes" - "encoding/json" - "net/http" - "net/http/httptest" - "testing" - - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" - "github.com/gin-gonic/gin" - "github.com/stretchr/testify/assert" -) - -func Test_Transfer(t *testing.T) { - envconfig.InitEnvVars() - - appinit.Init() - gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "60", - Mnemonic: "mobile attend orange oxygen valley fan grape suit tool fancy quality disease potato bean trophy", - }).Error - if err != nil { - t.Fatal(err) - } - - t.Run("Native token", func(t *testing.T) { - rr := httptest.NewRecorder() - - req := TransferRequest{ - UserId: "60", - To: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", - Amount: 1, - } - d, e := json.Marshal(req) - if e != nil { - t.Fatal(e) - } - c, _ := gin.CreateTestContext(rr) - httpReq, e := http.NewRequest("GET", "/", bytes.NewBuffer(d)) - if e != nil { - t.Fatal(e) - } - c.Request = httpReq - nativeTransfer(c) - - assert.Equal(t, 200, rr.Result().StatusCode) - - }) - -} diff --git a/api/v1/matic/transfer/transfer_native/types.go b/api/v1/matic/transfer/transfer_native/types.go deleted file mode 100644 index aa0179f..0000000 --- a/api/v1/matic/transfer/transfer_native/types.go +++ /dev/null @@ -1,11 +0,0 @@ -package transfer_native - -type TransferRequest struct { - UserId string `json:"userId" binding:"required"` - To string `json:"to" binding:"required"` - Amount int64 `json:"amount" binding:"required"` -} - -type TransferPayload struct { - TrasactionHash string -} diff --git a/api/v1/matic/verifySignature/types.go b/api/v1/matic/verifySignature/types.go deleted file mode 100644 index 6cdd4c1..0000000 --- a/api/v1/matic/verifySignature/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package verifysignature - -type VerifyRequest struct { - UserId string `json:"userId" binding:"required"` - Message string `json:"message" binding:"required"` - Signature string `json:"signature" binding:"required,hexadecimal,len=132"` -} diff --git a/api/v1/polygon/approve/approve.go b/api/v1/polygon/approve/approve.go new file mode 100644 index 0000000..80f66cc --- /dev/null +++ b/api/v1/polygon/approve/approve.go @@ -0,0 +1,49 @@ +package approve + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/approve") + { + + g.POST("", approveWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := ApprovePayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func approveWithSalt(c *gin.Context) { + network := "polygon" + var req ApproveWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("Invalid request body:%s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + + hash, err := polygon.ApproveERC721(req.Mnemonic, common.HexToAddress(req.ToAddress), common.HexToAddress(req.ContractAddress), *big.NewInt(req.TokenId)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve").SendD(c) + logo.Errorf("failed to approve to: %v from wallet of userId: %v, network: %v, contractAddr: %v, tokenId: %v, error: %s", req.ToAddress, + req.WalletAddress, network, req.ContractAddress, req.TokenId, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) + +} diff --git a/api/v1/matic/approve/approve_test.go b/api/v1/polygon/approve/approve_test.go similarity index 75% rename from api/v1/matic/approve/approve_test.go rename to api/v1/polygon/approve/approve_test.go index 97090ea..8a447c8 100644 --- a/api/v1/matic/approve/approve_test.go +++ b/api/v1/polygon/approve/approve_test.go @@ -8,12 +8,9 @@ import ( "net/http/httptest" "testing" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) @@ -23,14 +20,6 @@ func Test_Approve(t *testing.T) { appinit.Init() gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "60", - Mnemonic: "mobile attend orange oxygen valley fan grape suit tool fancy quality disease potato bean trophy", - }).Error - if err != nil { - t.Fatal(err) - } type network struct { name string @@ -54,8 +43,8 @@ func Test_Approve(t *testing.T) { for _, n := range networks { rr := httptest.NewRecorder() - req := ApproveRequest{ - UserId: "60", + req := ApproveWithSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", ToAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", ContractAddress: n.erc721Address, } @@ -69,7 +58,7 @@ func Test_Approve(t *testing.T) { t.Fatal(e) } c.Request = httpReq - approve(c) + approveWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } @@ -80,8 +69,8 @@ func Test_Approve(t *testing.T) { for _, n := range networks { rr := httptest.NewRecorder() - req := ApproveRequest{ - UserId: "60", + req := ApproveWithSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", ToAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", ContractAddress: n.erc721Address, } @@ -96,7 +85,7 @@ func Test_Approve(t *testing.T) { t.Fatal(e) } c.Request = httpReq - approve(c) + approveWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } @@ -105,8 +94,8 @@ func Test_Approve(t *testing.T) { for _, n := range networks { rr := httptest.NewRecorder() - req := ApproveRequest{ - UserId: "60", + req := ApproveWithSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", ToAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", ContractAddress: n.erc721Address, } @@ -123,7 +112,7 @@ func Test_Approve(t *testing.T) { t.Fatal(e) } c.Request = httpReq - approve(c) + approveWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } diff --git a/api/v1/polygon/approve/types.go b/api/v1/polygon/approve/types.go new file mode 100644 index 0000000..4486de9 --- /dev/null +++ b/api/v1/polygon/approve/types.go @@ -0,0 +1,14 @@ +package approve + +type ApproveWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ToAddress string `json:"toAddress" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} + +type ApprovePayload struct { + TrasactionHash string +} diff --git a/api/v1/polygon/approveAll/approveall.go b/api/v1/polygon/approveAll/approveall.go new file mode 100644 index 0000000..f7c144e --- /dev/null +++ b/api/v1/polygon/approveAll/approveall.go @@ -0,0 +1,46 @@ +package approveall + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/approve-all") + { + g.POST("", approveAllWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := TransferPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func approveAllWithSalt(c *gin.Context) { + network := "pollygon" + var req ApproveAllWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + hash, err := polygon.SetAprovalForAllErc721(req.Mnemonic, common.HexToAddress(req.OperatorAddress), common.HexToAddress(req.ContractAddress), req.Approved) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve all").SendD(c) + logo.Errorf("failed to approve all to operator: %v from wallet of userId: %v, network: %v, contractAddr: %v, error: %s", req.OperatorAddress, + req.WalletAddress, network, req.ContractAddress, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) +} diff --git a/api/v1/matic/approveAll/approveall_test.go b/api/v1/polygon/approveAll/approveall_test.go similarity index 80% rename from api/v1/matic/approveAll/approveall_test.go rename to api/v1/polygon/approveAll/approveall_test.go index 9b53b1e..f711d7a 100644 --- a/api/v1/matic/approveAll/approveall_test.go +++ b/api/v1/polygon/approveAll/approveall_test.go @@ -8,12 +8,9 @@ import ( "net/http/httptest" "testing" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) @@ -22,14 +19,6 @@ func Test_Approve(t *testing.T) { envconfig.InitEnvVars() appinit.Init() gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "60", - Mnemonic: "mobile attend orange oxygen valley fan grape suit tool fancy quality disease potato bean trophy", - }).Error - if err != nil { - t.Fatal(err) - } type network struct { name string @@ -68,7 +57,7 @@ func Test_Approve(t *testing.T) { t.Fatal(e) } c.Request = httpReq - approveAll(c) + approveAllWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } @@ -95,7 +84,7 @@ func Test_Approve(t *testing.T) { t.Fatal(e) } c.Request = httpReq - approveAll(c) + approveAllWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } @@ -122,7 +111,7 @@ func Test_Approve(t *testing.T) { t.Fatal(e) } c.Request = httpReq - approveAll(c) + approveAllWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } diff --git a/api/v1/polygon/approveAll/types.go b/api/v1/polygon/approveAll/types.go new file mode 100644 index 0000000..a7e2ed0 --- /dev/null +++ b/api/v1/polygon/approveAll/types.go @@ -0,0 +1,20 @@ +package approveall + +type ApproveAllRequest struct { + UserId string `json:"userId" binding:"required"` + OperatorAddress string `json:"operatorAddress" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + Approved bool `json:"approved" binding:"required"` +} + +type ApproveAllWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + OperatorAddress string `json:"operatorAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + Approved bool `json:"approved" binding:"required"` +} + +type TransferPayload struct { + TrasactionHash string +} diff --git a/api/v1/polygon/burn/burn.go b/api/v1/polygon/burn/burn.go new file mode 100644 index 0000000..b90cb78 --- /dev/null +++ b/api/v1/polygon/burn/burn.go @@ -0,0 +1,15 @@ +package burn + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/burn/burn_erc721" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/burn") + { + burn_erc721.ApplyRoutes(g) + } +} diff --git a/api/v1/polygon/burn/burn_erc721/burn_erc721.go b/api/v1/polygon/burn/burn_erc721/burn_erc721.go new file mode 100644 index 0000000..48c2fda --- /dev/null +++ b/api/v1/polygon/burn/burn_erc721/burn_erc721.go @@ -0,0 +1,46 @@ +package burn_erc721 + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc721") + { + g.POST("", burnWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := BurnPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func burnWithSalt(c *gin.Context) { + network := "polygon" + var req BurnWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("Invalid request body:%s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + + hash, err := polygon.BurnERC721(req.Mnemonic, common.HexToAddress(req.ContractAddress), *big.NewInt(req.TokenId)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to approve").SendD(c) + logo.Errorf("failed to burn tokenId: %v from wallet of: %v, network: %v, contractAddr: %v, error: %s", req.TokenId, req.WalletAddress, network, req.ContractAddress, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) +} diff --git a/api/v1/polygon/burn/burn_erc721/types.go b/api/v1/polygon/burn/burn_erc721/types.go new file mode 100644 index 0000000..61c8752 --- /dev/null +++ b/api/v1/polygon/burn/burn_erc721/types.go @@ -0,0 +1,13 @@ +package burn_erc721 + +type BurnWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} + +type BurnPayload struct { + TrasactionHash string +} diff --git a/api/v1/polygon/checkbalance/checkbalance.go b/api/v1/polygon/checkbalance/checkbalance.go new file mode 100644 index 0000000..d191d11 --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance.go @@ -0,0 +1,19 @@ +package checkbalance + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/checkbalance/checkbalance_erc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/checkbalance/checkbalance_erc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/checkbalance/checkbalance_native" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/checkbalance") + { + checkbalance_erc20.ApplyRoutes(g) + checkbalance_erc721.ApplyRoutes(g) + checkbalance_native.ApplyRoutes(g) + } +} diff --git a/api/v1/polygon/checkbalance/checkbalance_erc20/erc20.go b/api/v1/polygon/checkbalance/checkbalance_erc20/erc20.go new file mode 100644 index 0000000..edb4193 --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_erc20/erc20.go @@ -0,0 +1,46 @@ +package checkbalance_erc20 + +import ( + "net/http" + "strconv" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc20") + { + g.GET("/:contractAddress/:walletAddress", erc20CheckBalanceSalt) + } +} + +func erc20CheckBalanceSalt(c *gin.Context) { + paramContractAddress := c.Param("contractAddress") + paramWalletAddress := c.Param("walletAddress") + if len(paramWalletAddress) <= 0 { + httpo.NewErrorResponse(http.StatusBadRequest, "valid wallet address is required").SendD(c) + return + } + network := "polygon" + + balance, err := polygon.GetERC20BalanceInDecimalsFromWalletAddress(common.HexToAddress(paramWalletAddress), common.HexToAddress(paramContractAddress)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get balance").SendD(c) + logo.Errorf("failed to get ERC20 balance of wallet: %v , network: %v, contractAddr: %v , error: %s", paramWalletAddress, network, paramContractAddress, err) + return + } + + balanceInFloat, _ := balance.Float64() + balanceInString := strconv.FormatFloat(balanceInFloat, 'f', -1, 64) + + payload := CheckErc20BalancePayload{ + Balance: balanceInString, + } + httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) +} diff --git a/api/v1/polygon/checkbalance/checkbalance_erc20/erc20_test.go b/api/v1/polygon/checkbalance/checkbalance_erc20/erc20_test.go new file mode 100644 index 0000000..951944f --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_erc20/erc20_test.go @@ -0,0 +1,43 @@ +package checkbalance_erc20 + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_CheckBalance(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + t.Run("Fetch user balance for ERC20", func(t *testing.T) { + rr := httptest.NewRecorder() + c, _ := gin.CreateTestContext(rr) + + req := CheckErc20BalanceRequest{ + WalletAddress: "0x2d7882bedcbfddce29ba99965dd3cdf7fcb10a1e", + } + body, err := json.Marshal(req) + if err != nil { + t.Fatal(err) + } + + httpReq, err := http.NewRequest("POST", "/?erc20address=0x2d7882bedcbfddce29ba99965dd3cdf7fcb10a1e", bytes.NewBuffer(body)) + if err != nil { + t.Fatal(err) + } + c.Request = httpReq + erc20CheckBalanceSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + }) +} diff --git a/api/v1/polygon/checkbalance/checkbalance_erc20/type.go b/api/v1/polygon/checkbalance/checkbalance_erc20/type.go new file mode 100644 index 0000000..999858f --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_erc20/type.go @@ -0,0 +1,10 @@ +package checkbalance_erc20 + +type CheckErc20BalanceRequest struct { + WalletAddress string `json:"walletAddress" binding:"required"` + ContractAddr string `json:"contractAddr" binding:"required"` +} + +type CheckErc20BalancePayload struct { + Balance string `json:"balance"` +} diff --git a/api/v1/polygon/checkbalance/checkbalance_erc721/erc721.go b/api/v1/polygon/checkbalance/checkbalance_erc721/erc721.go new file mode 100644 index 0000000..85bcb02 --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_erc721/erc721.go @@ -0,0 +1,44 @@ +package checkbalance_erc721 + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc721") + { + g.POST("", erc721CheckBalanceWithSalt) + } +} + +func erc721CheckBalanceWithSalt(c *gin.Context) { + var req CheckErc721BalanceWithSalt + err := c.ShouldBindJSON(&req) + if err != nil { + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + network := "polygon" + + var balance *big.Int + balance, err = polygon.GetERC721Balance(req.Mnemonic, common.HexToAddress(req.ContractAddress)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get ERC721 balance").SendD(c) + logo.Errorf("failed to get ERC721 balance of wallet: %v , network: %v, contractAddress: %v , error: %s", req.WalletAddress, network, req.ContractAddress, err) + return + } + + payload := CheckErc721BalancePayload{ + Balance: balance.String(), + } + httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) +} diff --git a/api/v1/polygon/checkbalance/checkbalance_erc721/erc721_test.go b/api/v1/polygon/checkbalance/checkbalance_erc721/erc721_test.go new file mode 100644 index 0000000..82710eb --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_erc721/erc721_test.go @@ -0,0 +1,44 @@ +package checkbalance_erc721 + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_CheckBalance(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + t.Run("Fetch user balance for ERC721", func(t *testing.T) { + rr := httptest.NewRecorder() + c, _ := gin.CreateTestContext(rr) + + req := CheckErc721BalanceWithSalt{ + WalletAddress: "0x975362c36b6842d48d02DBD3A077745Fc1C64175", + ContractAddress: "0x975362c36b6842d48d02DBD3A077745Fc1C64175", + } + body, err := json.Marshal(req) + if err != nil { + t.Fatal(err) + } + + httpReq, err := http.NewRequest("POST", "", bytes.NewBuffer(body)) + if err != nil { + t.Fatal(err) + } + c.Request = httpReq + erc721CheckBalanceWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + }) +} diff --git a/api/v1/polygon/checkbalance/checkbalance_erc721/type.go b/api/v1/polygon/checkbalance/checkbalance_erc721/type.go new file mode 100644 index 0000000..c4a3b37 --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_erc721/type.go @@ -0,0 +1,16 @@ +package checkbalance_erc721 + +type CheckErc721BalanceRequest struct { + UserId string `json:"userId" binding:"required"` + ContractAddr string `json:"contractAddr" binding:"required"` +} + +type CheckErc721BalanceWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` +} + +type CheckErc721BalancePayload struct { + Balance string `json:"balance"` +} diff --git a/api/v1/polygon/checkbalance/checkbalance_native/native.go b/api/v1/polygon/checkbalance/checkbalance_native/native.go new file mode 100644 index 0000000..bdef3b9 --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_native/native.go @@ -0,0 +1,46 @@ +package checkbalance_native + +import ( + "math/big" + "net/http" + "strconv" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/native") + { + g.GET("/:walletAddress", nativeCheckBalanceWithSalt) + } +} + +func nativeCheckBalanceWithSalt(c *gin.Context) { + paramWalletAddress := c.Param("walletAddress") + if len(paramWalletAddress) <= 0 { + httpo.NewErrorResponse(http.StatusBadRequest, "valid wallet address is required").SendD(c) + return + } + network := "polygon" + + var balance *big.Float + balance, err := polygon.GetBalanceInDecimalsFromWalletAddress(paramWalletAddress) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get balance").SendD(c) + logo.Errorf("failed to get balance from wallet of userId: %v and network: %v, error: %s", paramWalletAddress, network, err) + return + } + + balanceInFloat, _ := balance.Float64() + balanceInString := strconv.FormatFloat(balanceInFloat, 'f', -1, 64) + + payload := CheckNativeBalancePayload{ + Balance: balanceInString, + } + httpo.NewSuccessResponse(200, "balance successfully fetched", payload).SendD(c) +} diff --git a/api/v1/polygon/checkbalance/checkbalance_native/native_test.go b/api/v1/polygon/checkbalance/checkbalance_native/native_test.go new file mode 100644 index 0000000..46be1f3 --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_native/native_test.go @@ -0,0 +1,43 @@ +package checkbalance_native + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_CheckBalance(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + t.Run("Fetch user balance", func(t *testing.T) { + rr := httptest.NewRecorder() + c, _ := gin.CreateTestContext(rr) + + req := CheckNativeBalanceRequest{ + UserId: "62", + } + body, err := json.Marshal(req) + if err != nil { + t.Fatal(err) + } + + httpReq, err := http.NewRequest("POST", "/", bytes.NewBuffer(body)) + if err != nil { + t.Fatal(err) + } + c.Request = httpReq + nativeCheckBalanceWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + }) +} diff --git a/api/v1/polygon/checkbalance/checkbalance_native/type.go b/api/v1/polygon/checkbalance/checkbalance_native/type.go new file mode 100644 index 0000000..d160c48 --- /dev/null +++ b/api/v1/polygon/checkbalance/checkbalance_native/type.go @@ -0,0 +1,9 @@ +package checkbalance_native + +type CheckNativeBalanceRequest struct { + UserId string `json:"userId" binding:"required"` +} + +type CheckNativeBalancePayload struct { + Balance string `json:"balance"` +} diff --git a/api/v1/polygon/matic.go b/api/v1/polygon/matic.go new file mode 100644 index 0000000..df5612b --- /dev/null +++ b/api/v1/polygon/matic.go @@ -0,0 +1,29 @@ +package polygon + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/approve" + approveall "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/approveAll" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/checkbalance" + signmessage "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/signMessage" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/transfer" + verifysignature "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/verifySignature" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/virtuacoinnft" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes Use the given Routes +func ApplyRoutes(r *gin.RouterGroup) { + v1 := r.Group("/polygon") + { + checkbalance.ApplyRoutes(v1) + verifysignature.ApplyRoutes(v1) + + signmessage.ApplyRoutes(v1) + // burn.ApplyRoutes(v1) + transfer.ApplyRoutes(v1) + approve.ApplyRoutes(v1) + approveall.ApplyRoutes(v1) + virtuacoinnft.ApplyRoutes(v1) + } +} diff --git a/api/v1/polygon/signMessage/signmessage.go b/api/v1/polygon/signMessage/signmessage.go new file mode 100644 index 0000000..523751b --- /dev/null +++ b/api/v1/polygon/signMessage/signmessage.go @@ -0,0 +1,46 @@ +package signmessage + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/sign-message") + { + + g.POST("", signMessage) + } +} + +func signMessage(c *gin.Context) { + var req SignMessageRequestWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + + return + } + + signature, err := polygon.SignMessage(req.Mnemonic, req.Message) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to sign").SendD(c) + logo.Errorf("failed to sign with walletAddress: %s", err) + return + } + + sendSuccessResponse(c, signature, req.WalletAddress) +} + +func sendSuccessResponse(c *gin.Context, signature string, userId string) { + payload := SignMessagePayload{ + Signature: signature, + } + httpo.NewSuccessResponse(200, "signature generated", payload).SendD(c) +} diff --git a/api/v1/polygon/signMessage/signmessage_test.go b/api/v1/polygon/signMessage/signmessage_test.go new file mode 100644 index 0000000..18928ac --- /dev/null +++ b/api/v1/polygon/signMessage/signmessage_test.go @@ -0,0 +1,50 @@ +package signmessage + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_SignMessage(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + _ = "0x844507295543d7dcb9a6bf5fa436437eaec309aa2edcfc694a407b8a30e84b464d02934432478d1e201440ec5712c6d7e15e66e1db672cf01d0cf9a1003926881c" + + t.Run("Native token", func(t *testing.T) { + message := "test message to sign" + rr := httptest.NewRecorder() + + req := SignMessageRequestWithSalt{ + WalletAddress: "", + Mnemonic: "test test test test test test", + Message: message, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http.NewRequest("GET", "/", bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + signMessage(c) + + assert.Equal(t, 200, rr.Result().StatusCode) + t.Fatal(rr.Body.String()) + + }) +} diff --git a/api/v1/polygon/signMessage/types.go b/api/v1/polygon/signMessage/types.go new file mode 100644 index 0000000..aa099f6 --- /dev/null +++ b/api/v1/polygon/signMessage/types.go @@ -0,0 +1,11 @@ +package signmessage + +type SignMessageRequestWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + Message string `json:"message" binding:"required"` +} + +type SignMessagePayload struct { + Signature string `json:"signature"` +} diff --git a/api/v1/polygon/transfer/transfer.go b/api/v1/polygon/transfer/transfer.go new file mode 100644 index 0000000..936f035 --- /dev/null +++ b/api/v1/polygon/transfer/transfer.go @@ -0,0 +1,19 @@ +package transfer + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/transfer/transfer_erc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/transfer/transfer_erc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/transfer/transfer_native" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/transfer") + { + transfer_erc20.ApplyRoutes(g) + transfer_erc721.ApplyRoutes(g) + transfer_native.ApplyRoutes(g) + } +} diff --git a/api/v1/polygon/transfer/transfer_erc20/erc20.go b/api/v1/polygon/transfer/transfer_erc20/erc20.go new file mode 100644 index 0000000..0f53cea --- /dev/null +++ b/api/v1/polygon/transfer/transfer_erc20/erc20.go @@ -0,0 +1,48 @@ +package transfer_erc20 + +import ( + "math/big" + "net/http" + "strconv" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc20") + { + + g.POST("", transferWithSalt) + } +} + +func transferWithSalt(c *gin.Context) { + network := "polygon" + var req TransferRequestSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + var hash string + amount := new(big.Int) + amountStr := strconv.FormatFloat(req.Amount, 'f', -1, 64) + amount.SetString(amountStr, 10) + + hash, err := polygon.TransferERC20(req.Mnemonic, common.HexToAddress(req.To), common.HexToAddress(req.ContractAddress), amount) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to transfer").SendD(c) + logo.Errorf("failed to transfer to: %v from wallet: %v , network: %v, contractAddr: %v , error: %s", req.To, req.WalletAddress, network, req.ContractAddress, err) + return + } + payload := TransferPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/polygon/transfer/transfer_erc20/erc20_test.go b/api/v1/polygon/transfer/transfer_erc20/erc20_test.go new file mode 100644 index 0000000..39f8ddb --- /dev/null +++ b/api/v1/polygon/transfer/transfer_erc20/erc20_test.go @@ -0,0 +1,67 @@ +package transfer_erc20 + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_Transfer(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + type network struct { + name string + chainId int64 + erc20Address string + } + networks := []network{ + { + name: "polygon", + chainId: 80001, + erc20Address: "0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e", + }, { + name: "ethereum", + chainId: 1, + erc20Address: "0x514910771af9ca656af840dff83e8264ecf986ca", + }, + } + + t.Run("ERC20 Token", func(t *testing.T) { + for _, n := range networks { + rr := httptest.NewRecorder() + + req := TransferRequestSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Mnemonic: "test test test test test test", + To: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Amount: 1, + ContractAddress: n.erc20Address, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http.NewRequest("GET", "", bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + transferWithSalt(c) + assert.Equal(t, 200, rr.Result().StatusCode) + } + + }) + +} diff --git a/api/v1/polygon/transfer/transfer_erc20/types.go b/api/v1/polygon/transfer/transfer_erc20/types.go new file mode 100644 index 0000000..72b6a03 --- /dev/null +++ b/api/v1/polygon/transfer/transfer_erc20/types.go @@ -0,0 +1,14 @@ +package transfer_erc20 + +type TransferPayload struct { + TrasactionHash string +} + +type TransferRequestSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + To string `json:"to" binding:"required"` + Amount float64 `json:"amount" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + Salt string `json:"salt" binding:"required"` +} diff --git a/api/v1/polygon/transfer/transfer_erc721/erc721.go b/api/v1/polygon/transfer/transfer_erc721/erc721.go new file mode 100644 index 0000000..f348e5e --- /dev/null +++ b/api/v1/polygon/transfer/transfer_erc721/erc721.go @@ -0,0 +1,41 @@ +package transfer_erc721 + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/erc721") + { + g.POST("", transferWithSalt) + } +} + +func transferWithSalt(c *gin.Context) { + network := "polygon" + var req TransferRequestSalt + err := c.ShouldBindJSON(&req) + if err != nil { + logo.Errorf("Invalid request body: %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + hash, err := polygon.TransferERC721(req.Mnemonic, common.HexToAddress(req.To), common.HexToAddress(req.ContractAddress), *big.NewInt(int64(req.TokenId))) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) + logo.Errorf("failed to tranfer to: %v from wallet: %v , network: %v, contractAddr: %v , error: %s", req.To, req.WalletAddress, network, req.ContractAddress, err) + return + } + + payload := TransferPayload{TrasactionHash: hash} + httpo.NewSuccessResponse(http.StatusOK, "trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/matic/transfer/transfer_erc721/erc721_test.go b/api/v1/polygon/transfer/transfer_erc721/erc721_test.go similarity index 68% rename from api/v1/matic/transfer/transfer_erc721/erc721_test.go rename to api/v1/polygon/transfer/transfer_erc721/erc721_test.go index 6faddb3..f614c19 100644 --- a/api/v1/matic/transfer/transfer_erc721/erc721_test.go +++ b/api/v1/polygon/transfer/transfer_erc721/erc721_test.go @@ -7,12 +7,9 @@ import ( "net/http/httptest" "testing" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/testingcommon" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) @@ -22,14 +19,6 @@ func Test_Transfer(t *testing.T) { appinit.Init() gin.SetMode(gin.TestMode) - t.Cleanup(testingcommon.DeleteCreatedEntities()) - err := store.DB.Model(&user.User{}).Create(&user.User{ - UserId: "60", - Mnemonic: "mobile attend orange oxygen valley fan grape suit tool fancy quality disease potato bean trophy", - }).Error - if err != nil { - t.Fatal(err) - } type network struct { name string @@ -71,7 +60,7 @@ func Test_Transfer(t *testing.T) { t.Fatal(e) } c.Request = httpReq - transfer(c) + transferWithSalt(c) assert.Equal(t, 200, rr.Result().StatusCode) } diff --git a/api/v1/polygon/transfer/transfer_erc721/types.go b/api/v1/polygon/transfer/transfer_erc721/types.go new file mode 100644 index 0000000..9d586f5 --- /dev/null +++ b/api/v1/polygon/transfer/transfer_erc721/types.go @@ -0,0 +1,22 @@ +package transfer_erc721 + +type TransferRequest struct { + UserId string `json:"userId" binding:"required"` + To string `json:"to" binding:"required"` + Amount int64 `json:"amount" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` +} + +type TransferPayload struct { + TrasactionHash string +} + +type TransferRequestSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + To string `json:"to" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} diff --git a/api/v1/polygon/transfer/transfer_native/native.go b/api/v1/polygon/transfer/transfer_native/native.go new file mode 100644 index 0000000..ab0a31b --- /dev/null +++ b/api/v1/polygon/transfer/transfer_native/native.go @@ -0,0 +1,48 @@ +package transfer_native + +import ( + "math" + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/native") + { + + g.POST("", nativeTransferWithSalt) + } +} + +func nativeTransferWithSalt(c *gin.Context) { + network := "polygon" + var req TransferRequestSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + // Convert float64 to bigInt + var amountInBigInt = big.NewInt(int64(req.Amount * math.Pow(10, 18))) + + var hash string + hash, err := polygon.Transfer(req.Mnemonic, common.HexToAddress(req.To), *amountInBigInt) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c) + logo.Errorf("failed to tranfer to: %v from wallet: %v and network: %v, error: %s", req.To, req.WalletAddress, network, err) + return + } + payload := TransferPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/polygon/transfer/transfer_native/native_test.go b/api/v1/polygon/transfer/transfer_native/native_test.go new file mode 100644 index 0000000..89ee9f9 --- /dev/null +++ b/api/v1/polygon/transfer/transfer_native/native_test.go @@ -0,0 +1,48 @@ +package transfer_native + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func Test_Transfer(t *testing.T) { + envconfig.InitEnvVars() + + appinit.Init() + gin.SetMode(gin.TestMode) + + t.Run("Native token", func(t *testing.T) { + rr := httptest.NewRecorder() + + req := TransferRequestSalt{ + WalletAddress: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Mnemonic: "test test test test test test", + To: "0x876FA09c042E6CA0c2f73AAe1DD7Bf712b6BF8f0", + Amount: 1, + } + d, e := json.Marshal(req) + if e != nil { + t.Fatal(e) + } + c, _ := gin.CreateTestContext(rr) + httpReq, e := http.NewRequest("GET", "/", bytes.NewBuffer(d)) + if e != nil { + t.Fatal(e) + } + c.Request = httpReq + nativeTransferWithSalt(c) + + assert.Equal(t, 200, rr.Result().StatusCode) + + }) + +} diff --git a/api/v1/polygon/transfer/transfer_native/types.go b/api/v1/polygon/transfer/transfer_native/types.go new file mode 100644 index 0000000..5b6fca4 --- /dev/null +++ b/api/v1/polygon/transfer/transfer_native/types.go @@ -0,0 +1,19 @@ +package transfer_native + +type TransferRequest struct { + UserId string `json:"userId" binding:"required"` + To string `json:"to" binding:"required"` + Amount int64 `json:"amount" binding:"required"` +} + +type TransferPayload struct { + TrasactionHash string +} + +type TransferRequestSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + To string `json:"to" binding:"required"` + Amount float64 `json:"amount" binding:"required"` + Salt string `json:"salt" binding:"required"` +} diff --git a/api/v1/polygon/verifySignature/types.go b/api/v1/polygon/verifySignature/types.go new file mode 100644 index 0000000..15784f7 --- /dev/null +++ b/api/v1/polygon/verifySignature/types.go @@ -0,0 +1,8 @@ +package verifysignature + +type VerifyRequest struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + Message string `json:"message" binding:"required"` + Signature string `json:"signature" binding:"required,hexadecimal,len=132"` +} diff --git a/api/v1/polygon/verifySignature/verifysigature.go b/api/v1/polygon/verifySignature/verifysigature.go new file mode 100644 index 0000000..c12ee94 --- /dev/null +++ b/api/v1/polygon/verifySignature/verifysigature.go @@ -0,0 +1,44 @@ +package verifysignature + +import ( + "fmt" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/verify-signature") + { + g.POST("", verifySignature) + } +} + +func verifySignature(c *gin.Context) { + network := "polygon" + var req VerifyRequest + if err := c.ShouldBindJSON(&req); err != nil { + err := fmt.Errorf("body is invalid: %w", err) + httpo.NewErrorResponse(http.StatusBadRequest, err.Error()).SendD(c) + return + } + + res, err := polygon.VerifySignature(req.Mnemonic, req.Message, req.Signature) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to verify signature").SendD(c) + logo.Errorf("failed to verify signature from wallet of userId: %v and network: %v, error: %s", + req.WalletAddress, network, err) + return + } + + if !res { + httpo.NewErrorResponse(httpo.SignatureDenied, "signature is invalid").Send(c, 403) + return + } + httpo.NewSuccessResponse(200, "signature is valid", nil).SendD(c) +} diff --git a/api/v1/polygon/virtuacoinnft/burn/burn.go b/api/v1/polygon/virtuacoinnft/burn/burn.go new file mode 100644 index 0000000..d4a1342 --- /dev/null +++ b/api/v1/polygon/virtuacoinnft/burn/burn.go @@ -0,0 +1,46 @@ +package burn + +import ( + "math/big" + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + virtuacoin "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon/virtuacoinnft" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/burn") + { + g.POST("", burnWithSalt) + } +} + +func sendSuccessResponse(c *gin.Context, hash string, userId string) { + payload := BurnPayload{ + TrasactionHash: hash, + } + httpo.NewSuccessResponse(200, "trasaction initiated", payload).SendD(c) +} + +func burnWithSalt(c *gin.Context) { + network := "polygon" + var req BurnWithSalt + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("Invalid request body:%s", err) + httpo.NewErrorResponse(http.StatusBadRequest, " Invalid body").SendD(c) + return + } + + hash, err := virtuacoin.Burn(req.Mnemonic, common.HexToAddress(req.ContractAddress), *big.NewInt(req.TokenId)) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to burn").SendD(c) + logo.Errorf("failed to burn tokenId: %v from wallet of: %v, network: %v, contractAddr: %v, error: %s", req.TokenId, req.WalletAddress, network, req.ContractAddress, err) + return + } + sendSuccessResponse(c, hash, req.WalletAddress) +} diff --git a/api/v1/polygon/virtuacoinnft/burn/types.go b/api/v1/polygon/virtuacoinnft/burn/types.go new file mode 100644 index 0000000..ecb8f5d --- /dev/null +++ b/api/v1/polygon/virtuacoinnft/burn/types.go @@ -0,0 +1,13 @@ +package burn + +type BurnWithSalt struct { + WalletAddress string `json:"walletAddress" binding:"required"` + Mnemonic string `json:"mnemonic" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + TokenId int64 `json:"tokenId" binding:"required"` + Salt string `json:"salt" binding:"required"` +} + +type BurnPayload struct { + TrasactionHash string +} diff --git a/api/v1/polygon/virtuacoinnft/delegateassetcreation/delegateassetcreation.go b/api/v1/polygon/virtuacoinnft/delegateassetcreation/delegateassetcreation.go new file mode 100644 index 0000000..0302730 --- /dev/null +++ b/api/v1/polygon/virtuacoinnft/delegateassetcreation/delegateassetcreation.go @@ -0,0 +1,44 @@ +package delegateassetcreation + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + virtuacoin "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon/virtuacoinnft" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/delegateassetcreation") + { + g.POST("", delegateAssetCreation) + } +} + +func delegateAssetCreation(c *gin.Context) { + network := "polygon" + var req DelegateAssetCreationRequest + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + erc721ContractAddr := common.HexToAddress(req.ContractAddress) + var hash string + hash, err := virtuacoin.DelegateAssetCreation(req.WalletAddress, erc721ContractAddr, req.MetadataURI) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to delegateAssetCreation").SendD(c) + logo.Errorf("failed to delegateAssetCreation of erc721 to wallet Address: %v , network: %v, contractAddr: %v, error: %s", req.WalletAddress, network, req.ContractAddress, err) + return + } + payload := DelegateErc721Payload{ + TrasactionHash: hash, + } + + httpo.NewSuccessResponse(200, "delegateAssetCreation trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/polygon/virtuacoinnft/delegateassetcreation/types.go b/api/v1/polygon/virtuacoinnft/delegateassetcreation/types.go new file mode 100644 index 0000000..17ef1a8 --- /dev/null +++ b/api/v1/polygon/virtuacoinnft/delegateassetcreation/types.go @@ -0,0 +1,11 @@ +package delegateassetcreation + +type DelegateAssetCreationRequest struct { + WalletAddress string `json:"walletAddress" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` + MetadataURI string `json:"metadataURI" binding:"required,min=1"` +} + +type DelegateErc721Payload struct { + TrasactionHash string +} diff --git a/api/v1/polygon/virtuacoinnft/grantrole/grantrole.go b/api/v1/polygon/virtuacoinnft/grantrole/grantrole.go new file mode 100644 index 0000000..5fed7d4 --- /dev/null +++ b/api/v1/polygon/virtuacoinnft/grantrole/grantrole.go @@ -0,0 +1,45 @@ +package grantrole + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + virtuacoin "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon/virtuacoinnft" + "github.com/ethereum/go-ethereum/common" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/grantrole") + { + g.POST("", grantRole) + } +} + +func grantRole(c *gin.Context) { + network := "polygon" + var req GrantRoleRequest + if err := c.ShouldBindJSON(&req); err != nil { + logo.Errorf("invalid request %s", err) + httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c) + return + } + + erc721ContractAddress := common.HexToAddress(req.ContractAddress) + + var hash string + hash, err := virtuacoin.GrantRole(req.RoleId, req.WalletAddress, erc721ContractAddress) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to grantRole").SendD(c) + logo.Errorf("failed to grantRole of %v in VirtuaCoinNFT to wallet Address: %v , network: %v, contractAddr: %v, error: %s", req.RoleId, req.WalletAddress, network, req.ContractAddress, err) + return + } + payload := GrantRolePayload{ + TrasactionHash: hash, + } + + httpo.NewSuccessResponse(200, "grantRole trasaction initiated", payload).SendD(c) +} diff --git a/api/v1/polygon/virtuacoinnft/grantrole/types.go b/api/v1/polygon/virtuacoinnft/grantrole/types.go new file mode 100644 index 0000000..ce8a517 --- /dev/null +++ b/api/v1/polygon/virtuacoinnft/grantrole/types.go @@ -0,0 +1,11 @@ +package grantrole + +type GrantRoleRequest struct { + RoleId string `json:"roleId" binding:"required"` + WalletAddress string `json:"walletAddress" binding:"required"` + ContractAddress string `json:"contractAddress" binding:"required"` +} + +type GrantRolePayload struct { + TrasactionHash string +} diff --git a/api/v1/polygon/virtuacoinnft/virtuacoinnft.go b/api/v1/polygon/virtuacoinnft/virtuacoinnft.go new file mode 100644 index 0000000..b048088 --- /dev/null +++ b/api/v1/polygon/virtuacoinnft/virtuacoinnft.go @@ -0,0 +1,18 @@ +package virtuacoinnft + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/virtuacoinnft/burn" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/virtuacoinnft/delegateassetcreation" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon/virtuacoinnft/grantrole" + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/virtuacoinnft") + { + delegateassetcreation.ApplyRoutes(g) + grantrole.ApplyRoutes(g) + burn.ApplyRoutes(g) + } +} diff --git a/api/v1/register/register.go b/api/v1/register/register.go deleted file mode 100644 index 5c3407d..0000000 --- a/api/v1/register/register.go +++ /dev/null @@ -1,34 +0,0 @@ -package register - -import ( - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/register") - { - - g.GET("", register) - } -} - -func register(c *gin.Context) { - uid, err := user.AddUser() - if err != nil { - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to add user").SendD(c) - logo.Errorf("failed to add user, error: %s", err) - - } else { - payload := RegisterPayload{ - Uid: uid, - } - httpo.NewSuccessResponse(200, "user registration successfull", payload).SendD(c) - } -} diff --git a/api/v1/register/types.go b/api/v1/register/types.go deleted file mode 100644 index b1f64a6..0000000 --- a/api/v1/register/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package register - -type RegisterPayload struct { - Uid string `json:"userId"` -} diff --git a/api/v1/setlock/setlock.go b/api/v1/setlock/setlock.go deleted file mode 100644 index fdb5726..0000000 --- a/api/v1/setlock/setlock.go +++ /dev/null @@ -1,45 +0,0 @@ -package setlock - -import ( - "errors" - "fmt" - "net/http" - - "github.com/TheLazarusNetwork/go-helpers/httpo" - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/user" - - "github.com/gin-gonic/gin" -) - -// ApplyRoutes applies router to gin Router -func ApplyRoutes(r *gin.RouterGroup) { - g := r.Group("/set-lock") - { - g.POST("", setLock) - } -} - -func setLock(c *gin.Context) { - var req SetLockRequest - err := c.ShouldBindJSON(&req) - if err != nil { - err := fmt.Errorf("body is invalid: %w", err) - httpo.NewErrorResponse(http.StatusBadRequest, err.Error()).SendD(c) - return - } - err = user.SetLockStatus(req.Uid, *req.LockStatus) - if err != nil { - if errors.Is(user.ErrNoRecordFound, err) { - httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404) - return - } - httpo.NewErrorResponse(http.StatusInternalServerError, "failed to set lock status").SendD(c) - logo.Errorf("failed to set lock status for user with id: %s, error: %s", req.Uid, err) - return - } else if *req.LockStatus { - httpo.NewSuccessResponse(200, "user locked", nil).SendD(c) - } else { - httpo.NewSuccessResponse(200, "user unlocked", nil).SendD(c) - } -} diff --git a/api/v1/setlock/types.go b/api/v1/setlock/types.go deleted file mode 100644 index 66ae4d2..0000000 --- a/api/v1/setlock/types.go +++ /dev/null @@ -1,6 +0,0 @@ -package setlock - -type SetLockRequest struct { - LockStatus *bool `json:"lockStatus" binding:"required"` - Uid string `json:"userId" binding:"required"` -} diff --git a/api/v1/v1.go b/api/v1/v1.go index 5324155..1080d3f 100644 --- a/api/v1/v1.go +++ b/api/v1/v1.go @@ -1,9 +1,10 @@ package apiv1 import ( - "github.com/TheLazarusNetwork/superiad/api/v1/matic" - "github.com/TheLazarusNetwork/superiad/api/v1/register" - "github.com/TheLazarusNetwork/superiad/api/v1/setlock" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/bsc" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/ethereum" + polygon "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/polygon" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api/v1/wallet" "github.com/gin-gonic/gin" ) @@ -11,8 +12,10 @@ import ( func ApplyRoutes(r *gin.RouterGroup) { v1 := r.Group("/v1.0") { - register.ApplyRoutes(v1) - setlock.ApplyRoutes(v1) - matic.ApplyRoutes(v1) + // register.ApplyRoutes(v1) + wallet.ApplyRoutes(v1) + polygon.ApplyRoutes(v1) + bsc.ApplyRoutes(v1) + ethereum.ApplyRoutes(v1) } } diff --git a/api/v1/wallet/types.go b/api/v1/wallet/types.go new file mode 100644 index 0000000..7f08bcf --- /dev/null +++ b/api/v1/wallet/types.go @@ -0,0 +1,9 @@ +package wallet + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/models/wallet" +) + +type GeneratePayload struct { + Wallet wallet.Wallet `json:"wallet"` +} diff --git a/api/v1/wallet/wallet.go b/api/v1/wallet/wallet.go new file mode 100644 index 0000000..6a873ca --- /dev/null +++ b/api/v1/wallet/wallet.go @@ -0,0 +1,50 @@ +package wallet + +import ( + "net/http" + + "github.com/TheLazarusNetwork/go-helpers/httpo" + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/models/wallet" + + "github.com/gin-gonic/gin" +) + +// ApplyRoutes applies router to gin Router +func ApplyRoutes(r *gin.RouterGroup) { + g := r.Group("/wallet") + { + g.POST("", generateWallet) + g.GET("/:walletAddress", getWallet) + } +} + +func generateWallet(c *gin.Context) { + wallet, err := wallet.GenerateWallet() + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to generate wallet").SendD(c) + logo.Errorf("failed to generate wallet, error: %s", err) + + } else { + payload := GeneratePayload{ + Wallet: wallet, + } + httpo.NewSuccessResponse(200, "wallet creation successful", payload).SendD(c) + } +} + +func getWallet(c *gin.Context) { + paramWalletAddress := c.Param("walletAddress") + if len(paramWalletAddress) <= 0 { + httpo.NewErrorResponse(http.StatusBadRequest, "valid wallet address is required").SendD(c) + return + } + salt, err := wallet.GetWallet(paramWalletAddress) + if err != nil { + httpo.NewErrorResponse(http.StatusInternalServerError, "failed to get wallet").SendD(c) + logo.Errorf("failed to get wallet, error: %s", err) + } else { + payload := salt + httpo.NewSuccessResponse(200, "wallet fetched successful ", payload).SendD(c) + } +} diff --git a/app/app.go b/app/app.go index 8363677..680f4ed 100644 --- a/app/app.go +++ b/app/app.go @@ -1,8 +1,8 @@ package app import ( - "github.com/TheLazarusNetwork/superiad/app/stage/appinit" - "github.com/TheLazarusNetwork/superiad/app/stage/apprun" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/apprun" "github.com/gin-gonic/gin" ) diff --git a/app/stage/appinit/appinit.go b/app/stage/appinit/appinit.go index 3c6bd25..06c0b02 100644 --- a/app/stage/appinit/appinit.go +++ b/app/stage/appinit/appinit.go @@ -1,15 +1,13 @@ package appinit import ( - "github.com/TheLazarusNetwork/superiad/app/stage/appinit/dbconinit" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit/dbmigrate" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit/envinit" - "github.com/TheLazarusNetwork/superiad/app/stage/appinit/logoinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit/envinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit/logoinit" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app/stage/appinit/redisconn" ) func Init() { envinit.Init() logoinit.Init() - dbconinit.Init() - dbmigrate.Migrate() + redisconn.Init() } diff --git a/app/stage/appinit/dbconinit/dbconinit.go b/app/stage/appinit/dbconinit/dbconinit.go deleted file mode 100644 index 62bac21..0000000 --- a/app/stage/appinit/dbconinit/dbconinit.go +++ /dev/null @@ -1,47 +0,0 @@ -// Package dbconinit provides method to Init database -package dbconinit - -import ( - "fmt" - - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "gorm.io/driver/postgres" - "gorm.io/gorm" -) - -func Init() { - var ( - host = envconfig.EnvVars.DB_HOST - username = envconfig.EnvVars.DB_USERNAME - password = envconfig.EnvVars.DB_PASSWORD - dbname = envconfig.EnvVars.DB_NAME - port = envconfig.EnvVars.DB_PORT - ) - - dns := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable port=%d", - host, username, password, dbname, port) - - var err error - db, err := gorm.Open(postgres.New(postgres.Config{ - DSN: dns, - })) - if err != nil { - logo.Fatal("failed to connect database", err) - } - - // Store database in global store - store.DB = db - - // Get underlying sql database to ping it - sqlDb, err := db.DB() - if err != nil { - logo.Fatal("failed to ping database", err) - } - - // If ping fails then log error and exit - if err = sqlDb.Ping(); err != nil { - logo.Fatal("failed to ping database", err) - } -} diff --git a/app/stage/appinit/dbmigrate/dbmigrate.go b/app/stage/appinit/dbmigrate/dbmigrate.go deleted file mode 100644 index efcf80f..0000000 --- a/app/stage/appinit/dbmigrate/dbmigrate.go +++ /dev/null @@ -1,17 +0,0 @@ -// Package dbmigrate provides method to migrate models into database -package dbmigrate - -import ( - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/models/transaction" - "github.com/TheLazarusNetwork/superiad/models/user" - "github.com/TheLazarusNetwork/superiad/pkg/store" -) - -func Migrate() { - db := store.DB - err := db.AutoMigrate(&user.User{}, &transaction.Transaction{}) - if err != nil { - logo.Fatalf("failed to migrate models into database: %s", err) - } -} diff --git a/app/stage/appinit/envinit/envinit.go b/app/stage/appinit/envinit/envinit.go index 4df1551..1fe67e8 100644 --- a/app/stage/appinit/envinit/envinit.go +++ b/app/stage/appinit/envinit/envinit.go @@ -1,6 +1,6 @@ package envinit -import "github.com/TheLazarusNetwork/superiad/config/envconfig" +import "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" func Init() { envconfig.InitEnvVars() diff --git a/app/stage/appinit/logoinit/logoinit.go b/app/stage/appinit/logoinit/logoinit.go index 123cc4b..f4b1649 100644 --- a/app/stage/appinit/logoinit/logoinit.go +++ b/app/stage/appinit/logoinit/logoinit.go @@ -3,7 +3,7 @@ package logoinit import ( "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/pkg/environment" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/environment" "github.com/sirupsen/logrus" ) diff --git a/app/stage/appinit/redisconn/redisconn.go b/app/stage/appinit/redisconn/redisconn.go new file mode 100644 index 0000000..721ab21 --- /dev/null +++ b/app/stage/appinit/redisconn/redisconn.go @@ -0,0 +1,41 @@ +package redisconn + +import ( + "context" + "fmt" + + "github.com/go-redis/redis/v8" + + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/store" +) + +func Init() { + var ( + host = envconfig.EnvVars.REDIS_HOST + port = envconfig.EnvVars.REDIS_PORT + password = envconfig.EnvVars.REDIS_PASSWORD + ) + + addr := fmt.Sprintf("%s:%d", host, port) + + rds := redis.NewClient(&redis.Options{ + Addr: addr, + Password: password, // no password set + DB: 0, // use default DB + }) + + // Store database in global store + store.RDS = rds + + // Get underlying sql database to ping it + pong, err := rds.Ping(context.Background()).Result() + + // If ping fails then log error and exit + if err != nil { + logo.Fatal("failed to ping redis", err) + } + + fmt.Println(pong, err) +} diff --git a/app/stage/apprun/apprun.go b/app/stage/apprun/apprun.go index 8f9c5fc..5500f90 100644 --- a/app/stage/apprun/apprun.go +++ b/app/stage/apprun/apprun.go @@ -6,8 +6,8 @@ import ( "time" "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/api" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/api" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" ) diff --git a/config/envconfig/envconfig.go b/config/envconfig/envconfig.go index 7429e69..7a4aaa7 100644 --- a/config/envconfig/envconfig.go +++ b/config/envconfig/envconfig.go @@ -9,18 +9,23 @@ import ( ) type config struct { - APP_PORT int `env:"APP_PORT,notEmpty"` - GIN_MODE string `env:"GIN_MODE,notEmpty"` - DB_HOST string `env:"DB_HOST,notEmpty"` - DB_USERNAME string `env:"DB_USERNAME,notEmpty"` - DB_PASSWORD string `env:"DB_PASSWORD,notEmpty"` - DB_NAME string `env:"DB_NAME,notEmpty"` - DB_PORT int `env:"DB_PORT,notEmpty"` - ALLOWED_ORIGIN []string `env:"ALLOWED_ORIGIN,notEmpty" envSeparator:","` - NETWORK_RPC_URL_ETHEREUM string `env:"NETWORK_RPC_URL_ETHEREUM,notEmpty"` - NETWORK_RPC_URL_POLYGON string `env:"NETWORK_RPC_URL_POLYGON,notEmpty"` - TOKEN string `env:"TOKEN,notEmpty"` - APP_ENVIRONMENT string `env:"APP_ENVIRONMENT,notEmpty"` + APP_PORT int `env:"APP_PORT,notEmpty"` + GIN_MODE string `env:"GIN_MODE,notEmpty"` + REDIS_HOST string `env:"REDIS_HOST,notEmpty"` + REDIS_PORT int `env:"REDIS_PORT,notEmpty"` + REDIS_PASSWORD string `env:"REDIS_PASSWORD,notEmpty"` + REDIS_DB string `env:"REDIS_DB,notEmpty"` + ALLOWED_ORIGIN []string `env:"ALLOWED_ORIGIN,notEmpty" envSeparator:","` + NETWORK_RPC_URL_ETHEREUM string `env:"NETWORK_RPC_URL_ETHEREUM,notEmpty"` + NETWORK_RPC_URL_POLYGON string `env:"NETWORK_RPC_URL_POLYGON,notEmpty"` + NETWORK_RPC_URL_BSC string `env:"NETWORK_RPC_URL_BSC,notEmpty"` + TOKEN string `env:"TOKEN,notEmpty"` + APP_ENVIRONMENT string `env:"APP_ENVIRONMENT,notEmpty"` + OPERATOR_MNEMONIC string `env:"OPERATOR_MNEMONIC,notEmpty"` + VIRTUACOINNFT_CONTRACT_ADDRESS string `env:"VIRTUACOINNFT_CONTRACT_ADDRESS,notEmpty"` + CHAIN_ID_POLYGON int `env:"CHAIN_ID_POLYGON,notEmpty"` + CHAIN_ID_BSC int `env:"CHAIN_ID_BSC,notEmpty"` + CHAIN_ID_ETHEREUM int `env:"CHAIN_ID_ETHEREUM,notEmpty"` } var EnvVars config = config{} diff --git a/generated/virtuacoinnft/VirtuaCoinNFT.go b/generated/virtuacoinnft/VirtuaCoinNFT.go new file mode 100644 index 0000000..687aa96 --- /dev/null +++ b/generated/virtuacoinnft/VirtuaCoinNFT.go @@ -0,0 +1,2451 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package virtuacoinnft + +import ( + "errors" + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = errors.New + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription +) + +// VirtuacoinnftMetaData contains all meta data concerning the Virtuacoinnft contract. +var VirtuacoinnftMetaData = &bind.MetaData{ + ABI: "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"symbol\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"tokenID\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"creator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"metaDataURI\",\"type\":\"string\"}],\"name\":\"AssetCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"previousAdminRole\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"newAdminRole\",\"type\":\"bytes32\"}],\"name\":\"RoleAdminChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleGranted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"RoleRevoked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"VIRTUACOIN_ADMIN_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"VIRTUACOIN_CREATOR_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"VIRTUACOIN_OPERATOR_ROLE\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"burn\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"metadataURI\",\"type\":\"string\"}],\"name\":\"createAsset\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"creator\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"metadataURI\",\"type\":\"string\"}],\"name\":\"delegateAssetCreation\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleAdmin\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getRoleMember\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"getRoleMemberCount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"grantRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"hasRole\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"renounceRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"revokeRole\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenOfOwnerByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unpause\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", +} + +// VirtuacoinnftABI is the input ABI used to generate the binding from. +// Deprecated: Use VirtuacoinnftMetaData.ABI instead. +var VirtuacoinnftABI = VirtuacoinnftMetaData.ABI + +// Virtuacoinnft is an auto generated Go binding around an Ethereum contract. +type Virtuacoinnft struct { + VirtuacoinnftCaller // Read-only binding to the contract + VirtuacoinnftTransactor // Write-only binding to the contract + VirtuacoinnftFilterer // Log filterer for contract events +} + +// VirtuacoinnftCaller is an auto generated read-only Go binding around an Ethereum contract. +type VirtuacoinnftCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// VirtuacoinnftTransactor is an auto generated write-only Go binding around an Ethereum contract. +type VirtuacoinnftTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// VirtuacoinnftFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type VirtuacoinnftFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// VirtuacoinnftSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type VirtuacoinnftSession struct { + Contract *Virtuacoinnft // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// VirtuacoinnftCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type VirtuacoinnftCallerSession struct { + Contract *VirtuacoinnftCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// VirtuacoinnftTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type VirtuacoinnftTransactorSession struct { + Contract *VirtuacoinnftTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// VirtuacoinnftRaw is an auto generated low-level Go binding around an Ethereum contract. +type VirtuacoinnftRaw struct { + Contract *Virtuacoinnft // Generic contract binding to access the raw methods on +} + +// VirtuacoinnftCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type VirtuacoinnftCallerRaw struct { + Contract *VirtuacoinnftCaller // Generic read-only contract binding to access the raw methods on +} + +// VirtuacoinnftTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type VirtuacoinnftTransactorRaw struct { + Contract *VirtuacoinnftTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewVirtuacoinnft creates a new instance of Virtuacoinnft, bound to a specific deployed contract. +func NewVirtuacoinnft(address common.Address, backend bind.ContractBackend) (*Virtuacoinnft, error) { + contract, err := bindVirtuacoinnft(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Virtuacoinnft{VirtuacoinnftCaller: VirtuacoinnftCaller{contract: contract}, VirtuacoinnftTransactor: VirtuacoinnftTransactor{contract: contract}, VirtuacoinnftFilterer: VirtuacoinnftFilterer{contract: contract}}, nil +} + +// NewVirtuacoinnftCaller creates a new read-only instance of Virtuacoinnft, bound to a specific deployed contract. +func NewVirtuacoinnftCaller(address common.Address, caller bind.ContractCaller) (*VirtuacoinnftCaller, error) { + contract, err := bindVirtuacoinnft(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &VirtuacoinnftCaller{contract: contract}, nil +} + +// NewVirtuacoinnftTransactor creates a new write-only instance of Virtuacoinnft, bound to a specific deployed contract. +func NewVirtuacoinnftTransactor(address common.Address, transactor bind.ContractTransactor) (*VirtuacoinnftTransactor, error) { + contract, err := bindVirtuacoinnft(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &VirtuacoinnftTransactor{contract: contract}, nil +} + +// NewVirtuacoinnftFilterer creates a new log filterer instance of Virtuacoinnft, bound to a specific deployed contract. +func NewVirtuacoinnftFilterer(address common.Address, filterer bind.ContractFilterer) (*VirtuacoinnftFilterer, error) { + contract, err := bindVirtuacoinnft(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &VirtuacoinnftFilterer{contract: contract}, nil +} + +// bindVirtuacoinnft binds a generic wrapper to an already deployed contract. +func bindVirtuacoinnft(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(VirtuacoinnftABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Virtuacoinnft *VirtuacoinnftRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Virtuacoinnft.Contract.VirtuacoinnftCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Virtuacoinnft *VirtuacoinnftRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.VirtuacoinnftTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Virtuacoinnft *VirtuacoinnftRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.VirtuacoinnftTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Virtuacoinnft *VirtuacoinnftCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Virtuacoinnft.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Virtuacoinnft *VirtuacoinnftTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Virtuacoinnft *VirtuacoinnftTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.contract.Transact(opts, method, params...) +} + +// DEFAULTADMINROLE is a free data retrieval call binding the contract method 0xa217fddf. +// +// Solidity: function DEFAULT_ADMIN_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCaller) DEFAULTADMINROLE(opts *bind.CallOpts) ([32]byte, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "DEFAULT_ADMIN_ROLE") + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// DEFAULTADMINROLE is a free data retrieval call binding the contract method 0xa217fddf. +// +// Solidity: function DEFAULT_ADMIN_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftSession) DEFAULTADMINROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.DEFAULTADMINROLE(&_Virtuacoinnft.CallOpts) +} + +// DEFAULTADMINROLE is a free data retrieval call binding the contract method 0xa217fddf. +// +// Solidity: function DEFAULT_ADMIN_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) DEFAULTADMINROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.DEFAULTADMINROLE(&_Virtuacoinnft.CallOpts) +} + +// VIRTUACOINADMINROLE is a free data retrieval call binding the contract method 0x81628385. +// +// Solidity: function VIRTUACOIN_ADMIN_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCaller) VIRTUACOINADMINROLE(opts *bind.CallOpts) ([32]byte, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "VIRTUACOIN_ADMIN_ROLE") + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// VIRTUACOINADMINROLE is a free data retrieval call binding the contract method 0x81628385. +// +// Solidity: function VIRTUACOIN_ADMIN_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftSession) VIRTUACOINADMINROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.VIRTUACOINADMINROLE(&_Virtuacoinnft.CallOpts) +} + +// VIRTUACOINADMINROLE is a free data retrieval call binding the contract method 0x81628385. +// +// Solidity: function VIRTUACOIN_ADMIN_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) VIRTUACOINADMINROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.VIRTUACOINADMINROLE(&_Virtuacoinnft.CallOpts) +} + +// VIRTUACOINCREATORROLE is a free data retrieval call binding the contract method 0x535d98be. +// +// Solidity: function VIRTUACOIN_CREATOR_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCaller) VIRTUACOINCREATORROLE(opts *bind.CallOpts) ([32]byte, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "VIRTUACOIN_CREATOR_ROLE") + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// VIRTUACOINCREATORROLE is a free data retrieval call binding the contract method 0x535d98be. +// +// Solidity: function VIRTUACOIN_CREATOR_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftSession) VIRTUACOINCREATORROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.VIRTUACOINCREATORROLE(&_Virtuacoinnft.CallOpts) +} + +// VIRTUACOINCREATORROLE is a free data retrieval call binding the contract method 0x535d98be. +// +// Solidity: function VIRTUACOIN_CREATOR_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) VIRTUACOINCREATORROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.VIRTUACOINCREATORROLE(&_Virtuacoinnft.CallOpts) +} + +// VIRTUACOINOPERATORROLE is a free data retrieval call binding the contract method 0x9d5519d6. +// +// Solidity: function VIRTUACOIN_OPERATOR_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCaller) VIRTUACOINOPERATORROLE(opts *bind.CallOpts) ([32]byte, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "VIRTUACOIN_OPERATOR_ROLE") + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// VIRTUACOINOPERATORROLE is a free data retrieval call binding the contract method 0x9d5519d6. +// +// Solidity: function VIRTUACOIN_OPERATOR_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftSession) VIRTUACOINOPERATORROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.VIRTUACOINOPERATORROLE(&_Virtuacoinnft.CallOpts) +} + +// VIRTUACOINOPERATORROLE is a free data retrieval call binding the contract method 0x9d5519d6. +// +// Solidity: function VIRTUACOIN_OPERATOR_ROLE() view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) VIRTUACOINOPERATORROLE() ([32]byte, error) { + return _Virtuacoinnft.Contract.VIRTUACOINOPERATORROLE(&_Virtuacoinnft.CallOpts) +} + +// BalanceOf is a free data retrieval call binding the contract method 0x70a08231. +// +// Solidity: function balanceOf(address owner) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCaller) BalanceOf(opts *bind.CallOpts, owner common.Address) (*big.Int, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "balanceOf", owner) + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// BalanceOf is a free data retrieval call binding the contract method 0x70a08231. +// +// Solidity: function balanceOf(address owner) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftSession) BalanceOf(owner common.Address) (*big.Int, error) { + return _Virtuacoinnft.Contract.BalanceOf(&_Virtuacoinnft.CallOpts, owner) +} + +// BalanceOf is a free data retrieval call binding the contract method 0x70a08231. +// +// Solidity: function balanceOf(address owner) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) BalanceOf(owner common.Address) (*big.Int, error) { + return _Virtuacoinnft.Contract.BalanceOf(&_Virtuacoinnft.CallOpts, owner) +} + +// GetApproved is a free data retrieval call binding the contract method 0x081812fc. +// +// Solidity: function getApproved(uint256 tokenId) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftCaller) GetApproved(opts *bind.CallOpts, tokenId *big.Int) (common.Address, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "getApproved", tokenId) + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// GetApproved is a free data retrieval call binding the contract method 0x081812fc. +// +// Solidity: function getApproved(uint256 tokenId) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftSession) GetApproved(tokenId *big.Int) (common.Address, error) { + return _Virtuacoinnft.Contract.GetApproved(&_Virtuacoinnft.CallOpts, tokenId) +} + +// GetApproved is a free data retrieval call binding the contract method 0x081812fc. +// +// Solidity: function getApproved(uint256 tokenId) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) GetApproved(tokenId *big.Int) (common.Address, error) { + return _Virtuacoinnft.Contract.GetApproved(&_Virtuacoinnft.CallOpts, tokenId) +} + +// GetRoleAdmin is a free data retrieval call binding the contract method 0x248a9ca3. +// +// Solidity: function getRoleAdmin(bytes32 role) view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCaller) GetRoleAdmin(opts *bind.CallOpts, role [32]byte) ([32]byte, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "getRoleAdmin", role) + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// GetRoleAdmin is a free data retrieval call binding the contract method 0x248a9ca3. +// +// Solidity: function getRoleAdmin(bytes32 role) view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftSession) GetRoleAdmin(role [32]byte) ([32]byte, error) { + return _Virtuacoinnft.Contract.GetRoleAdmin(&_Virtuacoinnft.CallOpts, role) +} + +// GetRoleAdmin is a free data retrieval call binding the contract method 0x248a9ca3. +// +// Solidity: function getRoleAdmin(bytes32 role) view returns(bytes32) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) GetRoleAdmin(role [32]byte) ([32]byte, error) { + return _Virtuacoinnft.Contract.GetRoleAdmin(&_Virtuacoinnft.CallOpts, role) +} + +// GetRoleMember is a free data retrieval call binding the contract method 0x9010d07c. +// +// Solidity: function getRoleMember(bytes32 role, uint256 index) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftCaller) GetRoleMember(opts *bind.CallOpts, role [32]byte, index *big.Int) (common.Address, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "getRoleMember", role, index) + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// GetRoleMember is a free data retrieval call binding the contract method 0x9010d07c. +// +// Solidity: function getRoleMember(bytes32 role, uint256 index) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftSession) GetRoleMember(role [32]byte, index *big.Int) (common.Address, error) { + return _Virtuacoinnft.Contract.GetRoleMember(&_Virtuacoinnft.CallOpts, role, index) +} + +// GetRoleMember is a free data retrieval call binding the contract method 0x9010d07c. +// +// Solidity: function getRoleMember(bytes32 role, uint256 index) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) GetRoleMember(role [32]byte, index *big.Int) (common.Address, error) { + return _Virtuacoinnft.Contract.GetRoleMember(&_Virtuacoinnft.CallOpts, role, index) +} + +// GetRoleMemberCount is a free data retrieval call binding the contract method 0xca15c873. +// +// Solidity: function getRoleMemberCount(bytes32 role) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCaller) GetRoleMemberCount(opts *bind.CallOpts, role [32]byte) (*big.Int, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "getRoleMemberCount", role) + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// GetRoleMemberCount is a free data retrieval call binding the contract method 0xca15c873. +// +// Solidity: function getRoleMemberCount(bytes32 role) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftSession) GetRoleMemberCount(role [32]byte) (*big.Int, error) { + return _Virtuacoinnft.Contract.GetRoleMemberCount(&_Virtuacoinnft.CallOpts, role) +} + +// GetRoleMemberCount is a free data retrieval call binding the contract method 0xca15c873. +// +// Solidity: function getRoleMemberCount(bytes32 role) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) GetRoleMemberCount(role [32]byte) (*big.Int, error) { + return _Virtuacoinnft.Contract.GetRoleMemberCount(&_Virtuacoinnft.CallOpts, role) +} + +// HasRole is a free data retrieval call binding the contract method 0x91d14854. +// +// Solidity: function hasRole(bytes32 role, address account) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCaller) HasRole(opts *bind.CallOpts, role [32]byte, account common.Address) (bool, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "hasRole", role, account) + + if err != nil { + return *new(bool), err + } + + out0 := *abi.ConvertType(out[0], new(bool)).(*bool) + + return out0, err + +} + +// HasRole is a free data retrieval call binding the contract method 0x91d14854. +// +// Solidity: function hasRole(bytes32 role, address account) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftSession) HasRole(role [32]byte, account common.Address) (bool, error) { + return _Virtuacoinnft.Contract.HasRole(&_Virtuacoinnft.CallOpts, role, account) +} + +// HasRole is a free data retrieval call binding the contract method 0x91d14854. +// +// Solidity: function hasRole(bytes32 role, address account) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) HasRole(role [32]byte, account common.Address) (bool, error) { + return _Virtuacoinnft.Contract.HasRole(&_Virtuacoinnft.CallOpts, role, account) +} + +// IsApprovedForAll is a free data retrieval call binding the contract method 0xe985e9c5. +// +// Solidity: function isApprovedForAll(address owner, address operator) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCaller) IsApprovedForAll(opts *bind.CallOpts, owner common.Address, operator common.Address) (bool, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "isApprovedForAll", owner, operator) + + if err != nil { + return *new(bool), err + } + + out0 := *abi.ConvertType(out[0], new(bool)).(*bool) + + return out0, err + +} + +// IsApprovedForAll is a free data retrieval call binding the contract method 0xe985e9c5. +// +// Solidity: function isApprovedForAll(address owner, address operator) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftSession) IsApprovedForAll(owner common.Address, operator common.Address) (bool, error) { + return _Virtuacoinnft.Contract.IsApprovedForAll(&_Virtuacoinnft.CallOpts, owner, operator) +} + +// IsApprovedForAll is a free data retrieval call binding the contract method 0xe985e9c5. +// +// Solidity: function isApprovedForAll(address owner, address operator) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) IsApprovedForAll(owner common.Address, operator common.Address) (bool, error) { + return _Virtuacoinnft.Contract.IsApprovedForAll(&_Virtuacoinnft.CallOpts, owner, operator) +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_Virtuacoinnft *VirtuacoinnftCaller) Name(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "name") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_Virtuacoinnft *VirtuacoinnftSession) Name() (string, error) { + return _Virtuacoinnft.Contract.Name(&_Virtuacoinnft.CallOpts) +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) Name() (string, error) { + return _Virtuacoinnft.Contract.Name(&_Virtuacoinnft.CallOpts) +} + +// OwnerOf is a free data retrieval call binding the contract method 0x6352211e. +// +// Solidity: function ownerOf(uint256 tokenId) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftCaller) OwnerOf(opts *bind.CallOpts, tokenId *big.Int) (common.Address, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "ownerOf", tokenId) + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// OwnerOf is a free data retrieval call binding the contract method 0x6352211e. +// +// Solidity: function ownerOf(uint256 tokenId) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftSession) OwnerOf(tokenId *big.Int) (common.Address, error) { + return _Virtuacoinnft.Contract.OwnerOf(&_Virtuacoinnft.CallOpts, tokenId) +} + +// OwnerOf is a free data retrieval call binding the contract method 0x6352211e. +// +// Solidity: function ownerOf(uint256 tokenId) view returns(address) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) OwnerOf(tokenId *big.Int) (common.Address, error) { + return _Virtuacoinnft.Contract.OwnerOf(&_Virtuacoinnft.CallOpts, tokenId) +} + +// Paused is a free data retrieval call binding the contract method 0x5c975abb. +// +// Solidity: function paused() view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCaller) Paused(opts *bind.CallOpts) (bool, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "paused") + + if err != nil { + return *new(bool), err + } + + out0 := *abi.ConvertType(out[0], new(bool)).(*bool) + + return out0, err + +} + +// Paused is a free data retrieval call binding the contract method 0x5c975abb. +// +// Solidity: function paused() view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftSession) Paused() (bool, error) { + return _Virtuacoinnft.Contract.Paused(&_Virtuacoinnft.CallOpts) +} + +// Paused is a free data retrieval call binding the contract method 0x5c975abb. +// +// Solidity: function paused() view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) Paused() (bool, error) { + return _Virtuacoinnft.Contract.Paused(&_Virtuacoinnft.CallOpts) +} + +// SupportsInterface is a free data retrieval call binding the contract method 0x01ffc9a7. +// +// Solidity: function supportsInterface(bytes4 interfaceId) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCaller) SupportsInterface(opts *bind.CallOpts, interfaceId [4]byte) (bool, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "supportsInterface", interfaceId) + + if err != nil { + return *new(bool), err + } + + out0 := *abi.ConvertType(out[0], new(bool)).(*bool) + + return out0, err + +} + +// SupportsInterface is a free data retrieval call binding the contract method 0x01ffc9a7. +// +// Solidity: function supportsInterface(bytes4 interfaceId) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftSession) SupportsInterface(interfaceId [4]byte) (bool, error) { + return _Virtuacoinnft.Contract.SupportsInterface(&_Virtuacoinnft.CallOpts, interfaceId) +} + +// SupportsInterface is a free data retrieval call binding the contract method 0x01ffc9a7. +// +// Solidity: function supportsInterface(bytes4 interfaceId) view returns(bool) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) SupportsInterface(interfaceId [4]byte) (bool, error) { + return _Virtuacoinnft.Contract.SupportsInterface(&_Virtuacoinnft.CallOpts, interfaceId) +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_Virtuacoinnft *VirtuacoinnftCaller) Symbol(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "symbol") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_Virtuacoinnft *VirtuacoinnftSession) Symbol() (string, error) { + return _Virtuacoinnft.Contract.Symbol(&_Virtuacoinnft.CallOpts) +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) Symbol() (string, error) { + return _Virtuacoinnft.Contract.Symbol(&_Virtuacoinnft.CallOpts) +} + +// TokenByIndex is a free data retrieval call binding the contract method 0x4f6ccce7. +// +// Solidity: function tokenByIndex(uint256 index) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCaller) TokenByIndex(opts *bind.CallOpts, index *big.Int) (*big.Int, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "tokenByIndex", index) + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// TokenByIndex is a free data retrieval call binding the contract method 0x4f6ccce7. +// +// Solidity: function tokenByIndex(uint256 index) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftSession) TokenByIndex(index *big.Int) (*big.Int, error) { + return _Virtuacoinnft.Contract.TokenByIndex(&_Virtuacoinnft.CallOpts, index) +} + +// TokenByIndex is a free data retrieval call binding the contract method 0x4f6ccce7. +// +// Solidity: function tokenByIndex(uint256 index) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) TokenByIndex(index *big.Int) (*big.Int, error) { + return _Virtuacoinnft.Contract.TokenByIndex(&_Virtuacoinnft.CallOpts, index) +} + +// TokenOfOwnerByIndex is a free data retrieval call binding the contract method 0x2f745c59. +// +// Solidity: function tokenOfOwnerByIndex(address owner, uint256 index) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCaller) TokenOfOwnerByIndex(opts *bind.CallOpts, owner common.Address, index *big.Int) (*big.Int, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "tokenOfOwnerByIndex", owner, index) + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// TokenOfOwnerByIndex is a free data retrieval call binding the contract method 0x2f745c59. +// +// Solidity: function tokenOfOwnerByIndex(address owner, uint256 index) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftSession) TokenOfOwnerByIndex(owner common.Address, index *big.Int) (*big.Int, error) { + return _Virtuacoinnft.Contract.TokenOfOwnerByIndex(&_Virtuacoinnft.CallOpts, owner, index) +} + +// TokenOfOwnerByIndex is a free data retrieval call binding the contract method 0x2f745c59. +// +// Solidity: function tokenOfOwnerByIndex(address owner, uint256 index) view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) TokenOfOwnerByIndex(owner common.Address, index *big.Int) (*big.Int, error) { + return _Virtuacoinnft.Contract.TokenOfOwnerByIndex(&_Virtuacoinnft.CallOpts, owner, index) +} + +// TokenURI is a free data retrieval call binding the contract method 0xc87b56dd. +// +// Solidity: function tokenURI(uint256 tokenId) view returns(string) +func (_Virtuacoinnft *VirtuacoinnftCaller) TokenURI(opts *bind.CallOpts, tokenId *big.Int) (string, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "tokenURI", tokenId) + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// TokenURI is a free data retrieval call binding the contract method 0xc87b56dd. +// +// Solidity: function tokenURI(uint256 tokenId) view returns(string) +func (_Virtuacoinnft *VirtuacoinnftSession) TokenURI(tokenId *big.Int) (string, error) { + return _Virtuacoinnft.Contract.TokenURI(&_Virtuacoinnft.CallOpts, tokenId) +} + +// TokenURI is a free data retrieval call binding the contract method 0xc87b56dd. +// +// Solidity: function tokenURI(uint256 tokenId) view returns(string) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) TokenURI(tokenId *big.Int) (string, error) { + return _Virtuacoinnft.Contract.TokenURI(&_Virtuacoinnft.CallOpts, tokenId) +} + +// TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. +// +// Solidity: function totalSupply() view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCaller) TotalSupply(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _Virtuacoinnft.contract.Call(opts, &out, "totalSupply") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. +// +// Solidity: function totalSupply() view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftSession) TotalSupply() (*big.Int, error) { + return _Virtuacoinnft.Contract.TotalSupply(&_Virtuacoinnft.CallOpts) +} + +// TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. +// +// Solidity: function totalSupply() view returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftCallerSession) TotalSupply() (*big.Int, error) { + return _Virtuacoinnft.Contract.TotalSupply(&_Virtuacoinnft.CallOpts) +} + +// Approve is a paid mutator transaction binding the contract method 0x095ea7b3. +// +// Solidity: function approve(address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) Approve(opts *bind.TransactOpts, to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "approve", to, tokenId) +} + +// Approve is a paid mutator transaction binding the contract method 0x095ea7b3. +// +// Solidity: function approve(address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) Approve(to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Approve(&_Virtuacoinnft.TransactOpts, to, tokenId) +} + +// Approve is a paid mutator transaction binding the contract method 0x095ea7b3. +// +// Solidity: function approve(address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) Approve(to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Approve(&_Virtuacoinnft.TransactOpts, to, tokenId) +} + +// Burn is a paid mutator transaction binding the contract method 0x42966c68. +// +// Solidity: function burn(uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) Burn(opts *bind.TransactOpts, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "burn", tokenId) +} + +// Burn is a paid mutator transaction binding the contract method 0x42966c68. +// +// Solidity: function burn(uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) Burn(tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Burn(&_Virtuacoinnft.TransactOpts, tokenId) +} + +// Burn is a paid mutator transaction binding the contract method 0x42966c68. +// +// Solidity: function burn(uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) Burn(tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Burn(&_Virtuacoinnft.TransactOpts, tokenId) +} + +// CreateAsset is a paid mutator transaction binding the contract method 0x55b1f24e. +// +// Solidity: function createAsset(string metadataURI) returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftTransactor) CreateAsset(opts *bind.TransactOpts, metadataURI string) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "createAsset", metadataURI) +} + +// CreateAsset is a paid mutator transaction binding the contract method 0x55b1f24e. +// +// Solidity: function createAsset(string metadataURI) returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftSession) CreateAsset(metadataURI string) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.CreateAsset(&_Virtuacoinnft.TransactOpts, metadataURI) +} + +// CreateAsset is a paid mutator transaction binding the contract method 0x55b1f24e. +// +// Solidity: function createAsset(string metadataURI) returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) CreateAsset(metadataURI string) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.CreateAsset(&_Virtuacoinnft.TransactOpts, metadataURI) +} + +// DelegateAssetCreation is a paid mutator transaction binding the contract method 0x03e30209. +// +// Solidity: function delegateAssetCreation(address creator, string metadataURI) returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftTransactor) DelegateAssetCreation(opts *bind.TransactOpts, creator common.Address, metadataURI string) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "delegateAssetCreation", creator, metadataURI) +} + +// DelegateAssetCreation is a paid mutator transaction binding the contract method 0x03e30209. +// +// Solidity: function delegateAssetCreation(address creator, string metadataURI) returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftSession) DelegateAssetCreation(creator common.Address, metadataURI string) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.DelegateAssetCreation(&_Virtuacoinnft.TransactOpts, creator, metadataURI) +} + +// DelegateAssetCreation is a paid mutator transaction binding the contract method 0x03e30209. +// +// Solidity: function delegateAssetCreation(address creator, string metadataURI) returns(uint256) +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) DelegateAssetCreation(creator common.Address, metadataURI string) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.DelegateAssetCreation(&_Virtuacoinnft.TransactOpts, creator, metadataURI) +} + +// GrantRole is a paid mutator transaction binding the contract method 0x2f2ff15d. +// +// Solidity: function grantRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) GrantRole(opts *bind.TransactOpts, role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "grantRole", role, account) +} + +// GrantRole is a paid mutator transaction binding the contract method 0x2f2ff15d. +// +// Solidity: function grantRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) GrantRole(role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.GrantRole(&_Virtuacoinnft.TransactOpts, role, account) +} + +// GrantRole is a paid mutator transaction binding the contract method 0x2f2ff15d. +// +// Solidity: function grantRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) GrantRole(role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.GrantRole(&_Virtuacoinnft.TransactOpts, role, account) +} + +// Pause is a paid mutator transaction binding the contract method 0x8456cb59. +// +// Solidity: function pause() returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) Pause(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "pause") +} + +// Pause is a paid mutator transaction binding the contract method 0x8456cb59. +// +// Solidity: function pause() returns() +func (_Virtuacoinnft *VirtuacoinnftSession) Pause() (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Pause(&_Virtuacoinnft.TransactOpts) +} + +// Pause is a paid mutator transaction binding the contract method 0x8456cb59. +// +// Solidity: function pause() returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) Pause() (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Pause(&_Virtuacoinnft.TransactOpts) +} + +// RenounceRole is a paid mutator transaction binding the contract method 0x36568abe. +// +// Solidity: function renounceRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) RenounceRole(opts *bind.TransactOpts, role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "renounceRole", role, account) +} + +// RenounceRole is a paid mutator transaction binding the contract method 0x36568abe. +// +// Solidity: function renounceRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) RenounceRole(role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.RenounceRole(&_Virtuacoinnft.TransactOpts, role, account) +} + +// RenounceRole is a paid mutator transaction binding the contract method 0x36568abe. +// +// Solidity: function renounceRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) RenounceRole(role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.RenounceRole(&_Virtuacoinnft.TransactOpts, role, account) +} + +// RevokeRole is a paid mutator transaction binding the contract method 0xd547741f. +// +// Solidity: function revokeRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) RevokeRole(opts *bind.TransactOpts, role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "revokeRole", role, account) +} + +// RevokeRole is a paid mutator transaction binding the contract method 0xd547741f. +// +// Solidity: function revokeRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) RevokeRole(role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.RevokeRole(&_Virtuacoinnft.TransactOpts, role, account) +} + +// RevokeRole is a paid mutator transaction binding the contract method 0xd547741f. +// +// Solidity: function revokeRole(bytes32 role, address account) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) RevokeRole(role [32]byte, account common.Address) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.RevokeRole(&_Virtuacoinnft.TransactOpts, role, account) +} + +// SafeTransferFrom is a paid mutator transaction binding the contract method 0x42842e0e. +// +// Solidity: function safeTransferFrom(address from, address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) SafeTransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "safeTransferFrom", from, to, tokenId) +} + +// SafeTransferFrom is a paid mutator transaction binding the contract method 0x42842e0e. +// +// Solidity: function safeTransferFrom(address from, address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) SafeTransferFrom(from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.SafeTransferFrom(&_Virtuacoinnft.TransactOpts, from, to, tokenId) +} + +// SafeTransferFrom is a paid mutator transaction binding the contract method 0x42842e0e. +// +// Solidity: function safeTransferFrom(address from, address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) SafeTransferFrom(from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.SafeTransferFrom(&_Virtuacoinnft.TransactOpts, from, to, tokenId) +} + +// SafeTransferFrom0 is a paid mutator transaction binding the contract method 0xb88d4fde. +// +// Solidity: function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) SafeTransferFrom0(opts *bind.TransactOpts, from common.Address, to common.Address, tokenId *big.Int, data []byte) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "safeTransferFrom0", from, to, tokenId, data) +} + +// SafeTransferFrom0 is a paid mutator transaction binding the contract method 0xb88d4fde. +// +// Solidity: function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) SafeTransferFrom0(from common.Address, to common.Address, tokenId *big.Int, data []byte) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.SafeTransferFrom0(&_Virtuacoinnft.TransactOpts, from, to, tokenId, data) +} + +// SafeTransferFrom0 is a paid mutator transaction binding the contract method 0xb88d4fde. +// +// Solidity: function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) SafeTransferFrom0(from common.Address, to common.Address, tokenId *big.Int, data []byte) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.SafeTransferFrom0(&_Virtuacoinnft.TransactOpts, from, to, tokenId, data) +} + +// SetApprovalForAll is a paid mutator transaction binding the contract method 0xa22cb465. +// +// Solidity: function setApprovalForAll(address operator, bool approved) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) SetApprovalForAll(opts *bind.TransactOpts, operator common.Address, approved bool) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "setApprovalForAll", operator, approved) +} + +// SetApprovalForAll is a paid mutator transaction binding the contract method 0xa22cb465. +// +// Solidity: function setApprovalForAll(address operator, bool approved) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) SetApprovalForAll(operator common.Address, approved bool) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.SetApprovalForAll(&_Virtuacoinnft.TransactOpts, operator, approved) +} + +// SetApprovalForAll is a paid mutator transaction binding the contract method 0xa22cb465. +// +// Solidity: function setApprovalForAll(address operator, bool approved) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) SetApprovalForAll(operator common.Address, approved bool) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.SetApprovalForAll(&_Virtuacoinnft.TransactOpts, operator, approved) +} + +// TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. +// +// Solidity: function transferFrom(address from, address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) TransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "transferFrom", from, to, tokenId) +} + +// TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. +// +// Solidity: function transferFrom(address from, address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftSession) TransferFrom(from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.TransferFrom(&_Virtuacoinnft.TransactOpts, from, to, tokenId) +} + +// TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. +// +// Solidity: function transferFrom(address from, address to, uint256 tokenId) returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) TransferFrom(from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error) { + return _Virtuacoinnft.Contract.TransferFrom(&_Virtuacoinnft.TransactOpts, from, to, tokenId) +} + +// Unpause is a paid mutator transaction binding the contract method 0x3f4ba83a. +// +// Solidity: function unpause() returns() +func (_Virtuacoinnft *VirtuacoinnftTransactor) Unpause(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Virtuacoinnft.contract.Transact(opts, "unpause") +} + +// Unpause is a paid mutator transaction binding the contract method 0x3f4ba83a. +// +// Solidity: function unpause() returns() +func (_Virtuacoinnft *VirtuacoinnftSession) Unpause() (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Unpause(&_Virtuacoinnft.TransactOpts) +} + +// Unpause is a paid mutator transaction binding the contract method 0x3f4ba83a. +// +// Solidity: function unpause() returns() +func (_Virtuacoinnft *VirtuacoinnftTransactorSession) Unpause() (*types.Transaction, error) { + return _Virtuacoinnft.Contract.Unpause(&_Virtuacoinnft.TransactOpts) +} + +// VirtuacoinnftApprovalIterator is returned from FilterApproval and is used to iterate over the raw logs and unpacked data for Approval events raised by the Virtuacoinnft contract. +type VirtuacoinnftApprovalIterator struct { + Event *VirtuacoinnftApproval // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftApprovalIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftApproval) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftApproval) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftApprovalIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftApprovalIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftApproval represents a Approval event raised by the Virtuacoinnft contract. +type VirtuacoinnftApproval struct { + Owner common.Address + Approved common.Address + TokenId *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterApproval is a free log retrieval operation binding the contract event 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925. +// +// Solidity: event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterApproval(opts *bind.FilterOpts, owner []common.Address, approved []common.Address, tokenId []*big.Int) (*VirtuacoinnftApprovalIterator, error) { + + var ownerRule []interface{} + for _, ownerItem := range owner { + ownerRule = append(ownerRule, ownerItem) + } + var approvedRule []interface{} + for _, approvedItem := range approved { + approvedRule = append(approvedRule, approvedItem) + } + var tokenIdRule []interface{} + for _, tokenIdItem := range tokenId { + tokenIdRule = append(tokenIdRule, tokenIdItem) + } + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "Approval", ownerRule, approvedRule, tokenIdRule) + if err != nil { + return nil, err + } + return &VirtuacoinnftApprovalIterator{contract: _Virtuacoinnft.contract, event: "Approval", logs: logs, sub: sub}, nil +} + +// WatchApproval is a free log subscription operation binding the contract event 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925. +// +// Solidity: event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchApproval(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftApproval, owner []common.Address, approved []common.Address, tokenId []*big.Int) (event.Subscription, error) { + + var ownerRule []interface{} + for _, ownerItem := range owner { + ownerRule = append(ownerRule, ownerItem) + } + var approvedRule []interface{} + for _, approvedItem := range approved { + approvedRule = append(approvedRule, approvedItem) + } + var tokenIdRule []interface{} + for _, tokenIdItem := range tokenId { + tokenIdRule = append(tokenIdRule, tokenIdItem) + } + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "Approval", ownerRule, approvedRule, tokenIdRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftApproval) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Approval", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseApproval is a log parse operation binding the contract event 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925. +// +// Solidity: event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseApproval(log types.Log) (*VirtuacoinnftApproval, error) { + event := new(VirtuacoinnftApproval) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Approval", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftApprovalForAllIterator is returned from FilterApprovalForAll and is used to iterate over the raw logs and unpacked data for ApprovalForAll events raised by the Virtuacoinnft contract. +type VirtuacoinnftApprovalForAllIterator struct { + Event *VirtuacoinnftApprovalForAll // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftApprovalForAllIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftApprovalForAll) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftApprovalForAll) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftApprovalForAllIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftApprovalForAllIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftApprovalForAll represents a ApprovalForAll event raised by the Virtuacoinnft contract. +type VirtuacoinnftApprovalForAll struct { + Owner common.Address + Operator common.Address + Approved bool + Raw types.Log // Blockchain specific contextual infos +} + +// FilterApprovalForAll is a free log retrieval operation binding the contract event 0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31. +// +// Solidity: event ApprovalForAll(address indexed owner, address indexed operator, bool approved) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterApprovalForAll(opts *bind.FilterOpts, owner []common.Address, operator []common.Address) (*VirtuacoinnftApprovalForAllIterator, error) { + + var ownerRule []interface{} + for _, ownerItem := range owner { + ownerRule = append(ownerRule, ownerItem) + } + var operatorRule []interface{} + for _, operatorItem := range operator { + operatorRule = append(operatorRule, operatorItem) + } + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "ApprovalForAll", ownerRule, operatorRule) + if err != nil { + return nil, err + } + return &VirtuacoinnftApprovalForAllIterator{contract: _Virtuacoinnft.contract, event: "ApprovalForAll", logs: logs, sub: sub}, nil +} + +// WatchApprovalForAll is a free log subscription operation binding the contract event 0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31. +// +// Solidity: event ApprovalForAll(address indexed owner, address indexed operator, bool approved) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchApprovalForAll(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftApprovalForAll, owner []common.Address, operator []common.Address) (event.Subscription, error) { + + var ownerRule []interface{} + for _, ownerItem := range owner { + ownerRule = append(ownerRule, ownerItem) + } + var operatorRule []interface{} + for _, operatorItem := range operator { + operatorRule = append(operatorRule, operatorItem) + } + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "ApprovalForAll", ownerRule, operatorRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftApprovalForAll) + if err := _Virtuacoinnft.contract.UnpackLog(event, "ApprovalForAll", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseApprovalForAll is a log parse operation binding the contract event 0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31. +// +// Solidity: event ApprovalForAll(address indexed owner, address indexed operator, bool approved) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseApprovalForAll(log types.Log) (*VirtuacoinnftApprovalForAll, error) { + event := new(VirtuacoinnftApprovalForAll) + if err := _Virtuacoinnft.contract.UnpackLog(event, "ApprovalForAll", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftAssetCreatedIterator is returned from FilterAssetCreated and is used to iterate over the raw logs and unpacked data for AssetCreated events raised by the Virtuacoinnft contract. +type VirtuacoinnftAssetCreatedIterator struct { + Event *VirtuacoinnftAssetCreated // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftAssetCreatedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftAssetCreated) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftAssetCreated) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftAssetCreatedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftAssetCreatedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftAssetCreated represents a AssetCreated event raised by the Virtuacoinnft contract. +type VirtuacoinnftAssetCreated struct { + TokenID *big.Int + Creator common.Address + MetaDataURI string + Raw types.Log // Blockchain specific contextual infos +} + +// FilterAssetCreated is a free log retrieval operation binding the contract event 0x49b4e4c6879cdc85b51d8c3b572252aaa7842edb863810854acb6d2ed420d962. +// +// Solidity: event AssetCreated(uint256 tokenID, address indexed creator, string metaDataURI) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterAssetCreated(opts *bind.FilterOpts, creator []common.Address) (*VirtuacoinnftAssetCreatedIterator, error) { + + var creatorRule []interface{} + for _, creatorItem := range creator { + creatorRule = append(creatorRule, creatorItem) + } + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "AssetCreated", creatorRule) + if err != nil { + return nil, err + } + return &VirtuacoinnftAssetCreatedIterator{contract: _Virtuacoinnft.contract, event: "AssetCreated", logs: logs, sub: sub}, nil +} + +// WatchAssetCreated is a free log subscription operation binding the contract event 0x49b4e4c6879cdc85b51d8c3b572252aaa7842edb863810854acb6d2ed420d962. +// +// Solidity: event AssetCreated(uint256 tokenID, address indexed creator, string metaDataURI) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchAssetCreated(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftAssetCreated, creator []common.Address) (event.Subscription, error) { + + var creatorRule []interface{} + for _, creatorItem := range creator { + creatorRule = append(creatorRule, creatorItem) + } + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "AssetCreated", creatorRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftAssetCreated) + if err := _Virtuacoinnft.contract.UnpackLog(event, "AssetCreated", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseAssetCreated is a log parse operation binding the contract event 0x49b4e4c6879cdc85b51d8c3b572252aaa7842edb863810854acb6d2ed420d962. +// +// Solidity: event AssetCreated(uint256 tokenID, address indexed creator, string metaDataURI) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseAssetCreated(log types.Log) (*VirtuacoinnftAssetCreated, error) { + event := new(VirtuacoinnftAssetCreated) + if err := _Virtuacoinnft.contract.UnpackLog(event, "AssetCreated", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftPausedIterator is returned from FilterPaused and is used to iterate over the raw logs and unpacked data for Paused events raised by the Virtuacoinnft contract. +type VirtuacoinnftPausedIterator struct { + Event *VirtuacoinnftPaused // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftPausedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftPaused) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftPaused) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftPausedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftPausedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftPaused represents a Paused event raised by the Virtuacoinnft contract. +type VirtuacoinnftPaused struct { + Account common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterPaused is a free log retrieval operation binding the contract event 0x62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258. +// +// Solidity: event Paused(address account) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterPaused(opts *bind.FilterOpts) (*VirtuacoinnftPausedIterator, error) { + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "Paused") + if err != nil { + return nil, err + } + return &VirtuacoinnftPausedIterator{contract: _Virtuacoinnft.contract, event: "Paused", logs: logs, sub: sub}, nil +} + +// WatchPaused is a free log subscription operation binding the contract event 0x62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258. +// +// Solidity: event Paused(address account) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchPaused(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftPaused) (event.Subscription, error) { + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "Paused") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftPaused) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Paused", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParsePaused is a log parse operation binding the contract event 0x62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258. +// +// Solidity: event Paused(address account) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParsePaused(log types.Log) (*VirtuacoinnftPaused, error) { + event := new(VirtuacoinnftPaused) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Paused", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftRoleAdminChangedIterator is returned from FilterRoleAdminChanged and is used to iterate over the raw logs and unpacked data for RoleAdminChanged events raised by the Virtuacoinnft contract. +type VirtuacoinnftRoleAdminChangedIterator struct { + Event *VirtuacoinnftRoleAdminChanged // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftRoleAdminChangedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftRoleAdminChanged) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftRoleAdminChanged) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftRoleAdminChangedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftRoleAdminChangedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftRoleAdminChanged represents a RoleAdminChanged event raised by the Virtuacoinnft contract. +type VirtuacoinnftRoleAdminChanged struct { + Role [32]byte + PreviousAdminRole [32]byte + NewAdminRole [32]byte + Raw types.Log // Blockchain specific contextual infos +} + +// FilterRoleAdminChanged is a free log retrieval operation binding the contract event 0xbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff. +// +// Solidity: event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterRoleAdminChanged(opts *bind.FilterOpts, role [][32]byte, previousAdminRole [][32]byte, newAdminRole [][32]byte) (*VirtuacoinnftRoleAdminChangedIterator, error) { + + var roleRule []interface{} + for _, roleItem := range role { + roleRule = append(roleRule, roleItem) + } + var previousAdminRoleRule []interface{} + for _, previousAdminRoleItem := range previousAdminRole { + previousAdminRoleRule = append(previousAdminRoleRule, previousAdminRoleItem) + } + var newAdminRoleRule []interface{} + for _, newAdminRoleItem := range newAdminRole { + newAdminRoleRule = append(newAdminRoleRule, newAdminRoleItem) + } + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "RoleAdminChanged", roleRule, previousAdminRoleRule, newAdminRoleRule) + if err != nil { + return nil, err + } + return &VirtuacoinnftRoleAdminChangedIterator{contract: _Virtuacoinnft.contract, event: "RoleAdminChanged", logs: logs, sub: sub}, nil +} + +// WatchRoleAdminChanged is a free log subscription operation binding the contract event 0xbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff. +// +// Solidity: event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchRoleAdminChanged(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftRoleAdminChanged, role [][32]byte, previousAdminRole [][32]byte, newAdminRole [][32]byte) (event.Subscription, error) { + + var roleRule []interface{} + for _, roleItem := range role { + roleRule = append(roleRule, roleItem) + } + var previousAdminRoleRule []interface{} + for _, previousAdminRoleItem := range previousAdminRole { + previousAdminRoleRule = append(previousAdminRoleRule, previousAdminRoleItem) + } + var newAdminRoleRule []interface{} + for _, newAdminRoleItem := range newAdminRole { + newAdminRoleRule = append(newAdminRoleRule, newAdminRoleItem) + } + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "RoleAdminChanged", roleRule, previousAdminRoleRule, newAdminRoleRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftRoleAdminChanged) + if err := _Virtuacoinnft.contract.UnpackLog(event, "RoleAdminChanged", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseRoleAdminChanged is a log parse operation binding the contract event 0xbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff. +// +// Solidity: event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseRoleAdminChanged(log types.Log) (*VirtuacoinnftRoleAdminChanged, error) { + event := new(VirtuacoinnftRoleAdminChanged) + if err := _Virtuacoinnft.contract.UnpackLog(event, "RoleAdminChanged", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftRoleGrantedIterator is returned from FilterRoleGranted and is used to iterate over the raw logs and unpacked data for RoleGranted events raised by the Virtuacoinnft contract. +type VirtuacoinnftRoleGrantedIterator struct { + Event *VirtuacoinnftRoleGranted // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftRoleGrantedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftRoleGranted) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftRoleGranted) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftRoleGrantedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftRoleGrantedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftRoleGranted represents a RoleGranted event raised by the Virtuacoinnft contract. +type VirtuacoinnftRoleGranted struct { + Role [32]byte + Account common.Address + Sender common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterRoleGranted is a free log retrieval operation binding the contract event 0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d. +// +// Solidity: event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterRoleGranted(opts *bind.FilterOpts, role [][32]byte, account []common.Address, sender []common.Address) (*VirtuacoinnftRoleGrantedIterator, error) { + + var roleRule []interface{} + for _, roleItem := range role { + roleRule = append(roleRule, roleItem) + } + var accountRule []interface{} + for _, accountItem := range account { + accountRule = append(accountRule, accountItem) + } + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "RoleGranted", roleRule, accountRule, senderRule) + if err != nil { + return nil, err + } + return &VirtuacoinnftRoleGrantedIterator{contract: _Virtuacoinnft.contract, event: "RoleGranted", logs: logs, sub: sub}, nil +} + +// WatchRoleGranted is a free log subscription operation binding the contract event 0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d. +// +// Solidity: event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchRoleGranted(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftRoleGranted, role [][32]byte, account []common.Address, sender []common.Address) (event.Subscription, error) { + + var roleRule []interface{} + for _, roleItem := range role { + roleRule = append(roleRule, roleItem) + } + var accountRule []interface{} + for _, accountItem := range account { + accountRule = append(accountRule, accountItem) + } + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "RoleGranted", roleRule, accountRule, senderRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftRoleGranted) + if err := _Virtuacoinnft.contract.UnpackLog(event, "RoleGranted", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseRoleGranted is a log parse operation binding the contract event 0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d. +// +// Solidity: event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseRoleGranted(log types.Log) (*VirtuacoinnftRoleGranted, error) { + event := new(VirtuacoinnftRoleGranted) + if err := _Virtuacoinnft.contract.UnpackLog(event, "RoleGranted", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftRoleRevokedIterator is returned from FilterRoleRevoked and is used to iterate over the raw logs and unpacked data for RoleRevoked events raised by the Virtuacoinnft contract. +type VirtuacoinnftRoleRevokedIterator struct { + Event *VirtuacoinnftRoleRevoked // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftRoleRevokedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftRoleRevoked) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftRoleRevoked) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftRoleRevokedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftRoleRevokedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftRoleRevoked represents a RoleRevoked event raised by the Virtuacoinnft contract. +type VirtuacoinnftRoleRevoked struct { + Role [32]byte + Account common.Address + Sender common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterRoleRevoked is a free log retrieval operation binding the contract event 0xf6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b. +// +// Solidity: event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterRoleRevoked(opts *bind.FilterOpts, role [][32]byte, account []common.Address, sender []common.Address) (*VirtuacoinnftRoleRevokedIterator, error) { + + var roleRule []interface{} + for _, roleItem := range role { + roleRule = append(roleRule, roleItem) + } + var accountRule []interface{} + for _, accountItem := range account { + accountRule = append(accountRule, accountItem) + } + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "RoleRevoked", roleRule, accountRule, senderRule) + if err != nil { + return nil, err + } + return &VirtuacoinnftRoleRevokedIterator{contract: _Virtuacoinnft.contract, event: "RoleRevoked", logs: logs, sub: sub}, nil +} + +// WatchRoleRevoked is a free log subscription operation binding the contract event 0xf6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b. +// +// Solidity: event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchRoleRevoked(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftRoleRevoked, role [][32]byte, account []common.Address, sender []common.Address) (event.Subscription, error) { + + var roleRule []interface{} + for _, roleItem := range role { + roleRule = append(roleRule, roleItem) + } + var accountRule []interface{} + for _, accountItem := range account { + accountRule = append(accountRule, accountItem) + } + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "RoleRevoked", roleRule, accountRule, senderRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftRoleRevoked) + if err := _Virtuacoinnft.contract.UnpackLog(event, "RoleRevoked", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseRoleRevoked is a log parse operation binding the contract event 0xf6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b. +// +// Solidity: event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseRoleRevoked(log types.Log) (*VirtuacoinnftRoleRevoked, error) { + event := new(VirtuacoinnftRoleRevoked) + if err := _Virtuacoinnft.contract.UnpackLog(event, "RoleRevoked", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftTransferIterator is returned from FilterTransfer and is used to iterate over the raw logs and unpacked data for Transfer events raised by the Virtuacoinnft contract. +type VirtuacoinnftTransferIterator struct { + Event *VirtuacoinnftTransfer // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftTransferIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftTransfer) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftTransfer) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftTransferIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftTransferIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftTransfer represents a Transfer event raised by the Virtuacoinnft contract. +type VirtuacoinnftTransfer struct { + From common.Address + To common.Address + TokenId *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterTransfer is a free log retrieval operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. +// +// Solidity: event Transfer(address indexed from, address indexed to, uint256 indexed tokenId) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterTransfer(opts *bind.FilterOpts, from []common.Address, to []common.Address, tokenId []*big.Int) (*VirtuacoinnftTransferIterator, error) { + + var fromRule []interface{} + for _, fromItem := range from { + fromRule = append(fromRule, fromItem) + } + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + var tokenIdRule []interface{} + for _, tokenIdItem := range tokenId { + tokenIdRule = append(tokenIdRule, tokenIdItem) + } + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "Transfer", fromRule, toRule, tokenIdRule) + if err != nil { + return nil, err + } + return &VirtuacoinnftTransferIterator{contract: _Virtuacoinnft.contract, event: "Transfer", logs: logs, sub: sub}, nil +} + +// WatchTransfer is a free log subscription operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. +// +// Solidity: event Transfer(address indexed from, address indexed to, uint256 indexed tokenId) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchTransfer(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftTransfer, from []common.Address, to []common.Address, tokenId []*big.Int) (event.Subscription, error) { + + var fromRule []interface{} + for _, fromItem := range from { + fromRule = append(fromRule, fromItem) + } + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + var tokenIdRule []interface{} + for _, tokenIdItem := range tokenId { + tokenIdRule = append(tokenIdRule, tokenIdItem) + } + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "Transfer", fromRule, toRule, tokenIdRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftTransfer) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Transfer", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseTransfer is a log parse operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. +// +// Solidity: event Transfer(address indexed from, address indexed to, uint256 indexed tokenId) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseTransfer(log types.Log) (*VirtuacoinnftTransfer, error) { + event := new(VirtuacoinnftTransfer) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Transfer", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// VirtuacoinnftUnpausedIterator is returned from FilterUnpaused and is used to iterate over the raw logs and unpacked data for Unpaused events raised by the Virtuacoinnft contract. +type VirtuacoinnftUnpausedIterator struct { + Event *VirtuacoinnftUnpaused // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *VirtuacoinnftUnpausedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftUnpaused) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(VirtuacoinnftUnpaused) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *VirtuacoinnftUnpausedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *VirtuacoinnftUnpausedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// VirtuacoinnftUnpaused represents a Unpaused event raised by the Virtuacoinnft contract. +type VirtuacoinnftUnpaused struct { + Account common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterUnpaused is a free log retrieval operation binding the contract event 0x5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa. +// +// Solidity: event Unpaused(address account) +func (_Virtuacoinnft *VirtuacoinnftFilterer) FilterUnpaused(opts *bind.FilterOpts) (*VirtuacoinnftUnpausedIterator, error) { + + logs, sub, err := _Virtuacoinnft.contract.FilterLogs(opts, "Unpaused") + if err != nil { + return nil, err + } + return &VirtuacoinnftUnpausedIterator{contract: _Virtuacoinnft.contract, event: "Unpaused", logs: logs, sub: sub}, nil +} + +// WatchUnpaused is a free log subscription operation binding the contract event 0x5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa. +// +// Solidity: event Unpaused(address account) +func (_Virtuacoinnft *VirtuacoinnftFilterer) WatchUnpaused(opts *bind.WatchOpts, sink chan<- *VirtuacoinnftUnpaused) (event.Subscription, error) { + + logs, sub, err := _Virtuacoinnft.contract.WatchLogs(opts, "Unpaused") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(VirtuacoinnftUnpaused) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Unpaused", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseUnpaused is a log parse operation binding the contract event 0x5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa. +// +// Solidity: event Unpaused(address account) +func (_Virtuacoinnft *VirtuacoinnftFilterer) ParseUnpaused(log types.Log) (*VirtuacoinnftUnpaused, error) { + event := new(VirtuacoinnftUnpaused) + if err := _Virtuacoinnft.contract.UnpackLog(event, "Unpaused", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} diff --git a/go.mod b/go.mod index 3af49d0..ba52168 100644 --- a/go.mod +++ b/go.mod @@ -1,35 +1,37 @@ -module github.com/TheLazarusNetwork/superiad +module github.com/VirtuaTechnologies/VirtuaCoin_Wallet go 1.17 require ( github.com/TheLazarusNetwork/go-helpers/httpo v0.0.0-20221007050857-09c7bf66b39e github.com/TheLazarusNetwork/go-helpers/logo v0.0.0-20221006153943-716648cb2d49 - github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c + github.com/btcsuite/btcd v0.22.1 github.com/btcsuite/btcd/btcutil v1.1.0 github.com/caarlos0/env/v6 v6.10.1 github.com/ethereum/go-ethereum v1.10.15 github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.8.1 + github.com/go-redis/redis/v8 v8.11.5 github.com/golang-jwt/jwt/v4 v4.2.0 github.com/google/uuid v1.3.0 github.com/joho/godotenv v1.4.0 github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.8.0 github.com/tyler-smith/go-bip39 v1.1.0 - gorm.io/driver/postgres v1.3.10 - gorm.io/gorm v1.23.10 ) require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/VictoriaMetrics/fastcache v1.6.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.1.0 // indirect - github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-logfmt/logfmt v0.5.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect @@ -40,16 +42,6 @@ require ( github.com/gorilla/websocket v1.4.2 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect - github.com/jackc/chunkreader/v2 v2.0.1 // indirect - github.com/jackc/pgconn v1.13.0 // indirect - github.com/jackc/pgio v1.0.0 // indirect - github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgproto3/v2 v2.3.1 // indirect - github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect - github.com/jackc/pgtype v1.12.0 // indirect - github.com/jackc/pgx/v4 v4.17.2 // indirect - github.com/jinzhu/inflection v1.0.0 // indirect - github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/mattn/go-isatty v0.0.16 // indirect diff --git a/go.sum b/go.sum index 459600b..08db10c 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,6 @@ github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbt github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= -github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= -github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= @@ -67,15 +65,19 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= -github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c h1:lnAMg3ra/Gw4AkRMxrxYs8nrprWsHowg8H9zaYsJOo4= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= +github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= +github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= github.com/btcsuite/btcd/btcec/v2 v2.1.0 h1:Whmbo9yShKKG+WrUfYGFfgj77vYBiwhwBSJnM66TMKI= github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A= github.com/btcsuite/btcd/btcutil v1.1.0 h1:MO4klnGY+EWJdoWF12Wkuf4AWDBPMpZNeN/jRLrklUU= github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= @@ -91,21 +93,17 @@ github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.14.0/go.mod h1:EnwdgGMaFOruiPZRFSgn+TsQ3hQ7C/YWzIGLeu5c304= -github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= -github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= @@ -123,6 +121,8 @@ github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= @@ -160,7 +160,6 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= @@ -178,16 +177,17 @@ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= -github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU= @@ -211,6 +211,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= @@ -233,6 +234,7 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= @@ -259,6 +261,7 @@ github.com/huin/goupnp v1.0.2 h1:RfGLP+h3mvisuWEyybxNq5Eft3NWhHLPeUN72kpKZoI= github.com/huin/goupnp v1.0.2/go.mod h1:0dxJBVBHqTMjIUMkESDTNgOOx/Mw5wYIfyFmdzSamkM= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/flux v0.65.1/go.mod h1:J754/zds0vvpfwuq7Gc2wRdVwEodfpCFM7mYlOw2LqY= github.com/influxdata/influxdb v1.8.3/go.mod h1:JugdFhsvvI8gadxOI6noqNeeBHvWNTbfYGtiAn+2jhI= @@ -271,65 +274,11 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po= -github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0= -github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= -github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= -github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= -github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= -github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= -github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s= -github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= -github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY= -github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= -github.com/jackc/pgconn v1.13.0 h1:3L1XMNV2Zvca/8BYhzcRFS70Lr0WlDg16Di6SFGAbys= -github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI= -github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= -github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= -github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= -github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c= -github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc= -github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= -github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A= -github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= -github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= -github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg= -github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= -github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= -github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y= -github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg= -github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= -github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= -github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= -github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= -github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM= -github.com/jackc/pgtype v1.12.0 h1:Dlq8Qvcch7kiehm8wPGIW0W3KsCCHJnRacKW0UM8n5w= -github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= -github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y= -github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= -github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= -github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= -github.com/jackc/pgx/v4 v4.17.2 h1:0Ut0rpeKwvIVbMQ1KbMBU4h6wxehBI535LK6Flheh8E= -github.com/jackc/pgx/v4 v4.17.2/go.mod h1:lcxIZN44yMIrWI78a5CpucdD14hX0SBDbNRvjDBItsw= -github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= -github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= @@ -354,14 +303,12 @@ github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM52 github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg= github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= @@ -372,25 +319,17 @@ github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2 github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8= -github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -417,21 +356,27 @@ github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 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/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= @@ -472,23 +417,14 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= -github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= -github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= -github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= -github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= -github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -501,7 +437,6 @@ github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 h1:Gb2Tyox57N github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -534,39 +469,27 @@ github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+ github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= -go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190909091759-094676da4a83/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b h1:huxqepDufQpLLIRXiVkTvnxrzJlpwmIWAObmcCcUFr0= golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -612,7 +535,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -621,6 +543,7 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20221004154528-8021a29435af h1:wv66FM3rLZGPdxpYL+ApnDe2HzHcTFta3z5nsc13wI4= @@ -648,9 +571,7 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -672,6 +593,7 @@ golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -682,6 +604,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= @@ -714,29 +637,23 @@ golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200108203644-89082a384178/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -786,6 +703,7 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= @@ -796,7 +714,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= @@ -816,11 +733,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.3.10 h1:Fsd+pQpFMGlGxxVMUPJhNo8gG8B1lKtk8QQ4/VZZAJw= -gorm.io/driver/postgres v1.3.10/go.mod h1:whNfh5WhhHs96honoLjBAMwJGYEuA3m1hvgUbNXhPCw= -gorm.io/gorm v1.23.7/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= -gorm.io/gorm v1.23.10 h1:4Ne9ZbzID9GUxRkllxN4WjJKpsHx8YbKvekVdgyWh24= -gorm.io/gorm v1.23.10/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/main.go b/main.go index a941f00..bc8a33c 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/TheLazarusNetwork/superiad/app" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/app" ) func main() { diff --git a/models/transaction/Transaction.go b/models/transaction/Transaction.go deleted file mode 100644 index 3a336a6..0000000 --- a/models/transaction/Transaction.go +++ /dev/null @@ -1,6 +0,0 @@ -package transaction - -type Transaction struct { - UserId string `gorm:"not null"` - TrasactionHash string `gorm:"primary_key"` -} diff --git a/models/user/User.go b/models/user/User.go deleted file mode 100644 index dbfcacb..0000000 --- a/models/user/User.go +++ /dev/null @@ -1,86 +0,0 @@ -package user - -import ( - "errors" - - "github.com/TheLazarusNetwork/superiad/models/transaction" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" - "github.com/google/uuid" -) - -var ( - ErrNoRecordFound = errors.New("no record found") -) - -type User struct { - UserId string `json:"userId" gorm:"primary_key"` - Mnemonic string `json:"-" gorm:"unique;not null"` - Transactions []transaction.Transaction `json:"transactions" gorm:"foreignKey:UserId"` - IsUserLocked bool `json:"isUserLocked"` -} - -func AddUser() (string, error) { - mnemonic, err := wallet.GenerateMnemonic() - if err != nil { - return "", err - } - db := store.DB - userId := uuid.NewString() - newUser := User{ - UserId: userId, - Mnemonic: *mnemonic, - } - if err := db.Model(&newUser).Create(&newUser).Error; err != nil { - return "", err - } else { - return userId, nil - } -} - -func AddTrasactionHash(userId string, hash string) error { - db := store.DB - trx := transaction.Transaction{UserId: userId, TrasactionHash: hash} - association := db.Model(&User{UserId: userId}).Association("Transactions") - err := association.Error - if err != nil { - return err - } - err = association.Append(&trx) - if err != nil { - return err - } - return nil -} - -func SetLockStatus(userId string, lockStatus bool) error { - db := store.DB - res := db.Model(&User{}).Where("user_id = ?", userId).Update("is_user_locked", lockStatus) - if err := res.Error; err != nil { - return err - } - if res.RowsAffected == 0 { - return ErrNoRecordFound - } - - return nil -} - -func GetMnemonic(userId string) (mnemonic string, err error) { - user, err := GetUser(userId) - if err != nil { - return "", err - } else { - return user.Mnemonic, nil - } -} - -func GetUser(userId string) (user User, err error) { - db := store.DB - err = db.Model(&User{}).Where("user_id = ?", userId).First(&user).Error - if err != nil { - return User{}, err - } else { - return user, nil - } -} diff --git a/models/wallet/Wallet.go b/models/wallet/Wallet.go new file mode 100644 index 0000000..3d7e8da --- /dev/null +++ b/models/wallet/Wallet.go @@ -0,0 +1,67 @@ +package wallet + +import ( + "context" + "errors" + + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/store" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/google/uuid" +) + +var ( + ErrNoRecordFound = errors.New("no record found") +) + +type Wallet struct { + Address string `json:"address"` + Salt string `json:"salt"` + Mnemonic string `json:"mnemonic"` + PrivateKey string `json:"privateKey"` +} + +func GenerateWallet() (Wallet, error) { + // Generate Mnemonic and derive private/public keys + mnemonic, err := wallet.GenerateMnemonic() + if err != nil { + logo.Fatal("failed to generate wallet", err) + return Wallet{}, err + } + privKey, err := polygon.GetWalletPrivateKey(*mnemonic) + if err != nil { + logo.Fatal("failed to derive wallet private key", err) + return Wallet{}, err + } + walletAddress, err := polygon.GetWalletAddres(*mnemonic) + if err != nil { + logo.Fatal("failed to generate wallet", err) + return Wallet{}, err + } + salt := uuid.NewString() + + err = store.RDS.Set(context.Background(), walletAddress, salt, 0).Err() + if err != nil { + logo.Fatal("failed to generate wallet", err) + return Wallet{}, err + } + + newWallet := Wallet{ + Address: walletAddress, + Salt: salt, + Mnemonic: *mnemonic, + PrivateKey: privKey, + } + return newWallet, nil +} + +func GetWallet(walletAddress string) (string, error) { + // Find the wallet address based on the salt + salt, err := store.RDS.Get(context.Background(), walletAddress).Result() + if err != nil { + logo.Errorf("failed to query wallet address from redis, error: %s", err) + return "", err + } + return salt, nil +} diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index b589bdc..353a8c8 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -4,7 +4,7 @@ package environment import ( "log" - "github.com/TheLazarusNetwork/superiad/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" ) type Environment int diff --git a/pkg/network/bsc/approveErc721.go b/pkg/network/bsc/approveErc721.go new file mode 100644 index 0000000..d132022 --- /dev/null +++ b/pkg/network/bsc/approveErc721.go @@ -0,0 +1,33 @@ +package bsc + +import ( + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func ApproveERC721(mnemonic string, toAddress common.Address, contractAddr common.Address, tokenId big.Int) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + chainId, err := GetChainId() + if err != nil { + return "", err + } + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "approve", toAddress, &tokenId) + if err != nil { + return "", err + } + return tx.Hash().Hex(), nil + +} diff --git a/pkg/network/bsc/bscnetwork.go b/pkg/network/bsc/bscnetwork.go new file mode 100644 index 0000000..2c65bcf --- /dev/null +++ b/pkg/network/bsc/bscnetwork.go @@ -0,0 +1,102 @@ +package bsc + +import ( + "context" + "encoding/hex" + "fmt" + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" +) + +func GetChainId() (int, error) { + return envconfig.EnvVars.CHAIN_ID_BSC, nil +} + +func GetPath() string { + return "m/44H/60H/0H/0/0" +} + +func GetRpcUrl() string { + return envconfig.EnvVars.NETWORK_RPC_URL_BSC +} + +func GetBalance(mnemonic string) (*big.Int, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return nil, err + } + publicKey := privKey.PublicKey + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, fmt.Errorf("failed to dial rpc client :%w", err) + } + bal, err := client.BalanceAt(context.Background(), crypto.PubkeyToAddress(publicKey), nil) + if err != nil { + return nil, fmt.Errorf("failed to call BalanceAt :%w", err) + } + return bal, nil +} + +func GetBalanceFromWalletAddress(walletAddress string) (*big.Int, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, fmt.Errorf("failed to dial rpc client :%w", err) + } + bal, err := client.BalanceAt(context.Background(), common.HexToAddress(walletAddress), nil) + if err != nil { + return nil, fmt.Errorf("failed to call BalanceAt :%w", err) + } + return bal, nil +} + +func GetBalanceInDecimalsFromWalletAddress(walletAddress string) (*big.Float, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, fmt.Errorf("failed to dial rpc client :%w", err) + } + bal, err := client.BalanceAt(context.Background(), common.HexToAddress(walletAddress), nil) + if err != nil { + return nil, fmt.Errorf("failed to call BalanceAt :%w", err) + } + + ether := big.NewFloat(0).SetInt(big.NewInt(1000000000000000000)) + balanceInDecimals := big.NewFloat(0).SetInt(bal) + balanceInDecimals.Quo(balanceInDecimals, ether) + return balanceInDecimals, nil +} + +func GetNetworkInfo() (*networkInfo, error) { + chainId, err := GetChainId() + if err != nil { + return nil, err + } + return &networkInfo{ + Name: "bsc", + ChainId: big.NewInt(int64(chainId)), + }, nil +} + +func GetWalletAddres(mnemonic string) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + walletAddr := crypto.PubkeyToAddress(privKey.PublicKey) + + return walletAddr.String(), nil +} + +func GetWalletPrivateKey(mnemonic string) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + privateKeyBytes := crypto.FromECDSA(privKey) + + return hex.EncodeToString(privateKeyBytes[2:]), nil +} diff --git a/pkg/network/bsc/burnErc721.go b/pkg/network/bsc/burnErc721.go new file mode 100644 index 0000000..a7c4150 --- /dev/null +++ b/pkg/network/bsc/burnErc721.go @@ -0,0 +1,32 @@ +package bsc + +import ( + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func BurnERC721(mnemonic string, contractAddr common.Address, tokenId big.Int) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + chainId, err := GetChainId() + if err != nil { + return "", err + } + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "burn", &tokenId) + if err != nil { + return "", err + } + return tx.Hash().Hex(), nil +} diff --git a/pkg/network/bsc/getErc20Bal.go b/pkg/network/bsc/getErc20Bal.go new file mode 100644 index 0000000..ac91c56 --- /dev/null +++ b/pkg/network/bsc/getErc20Bal.go @@ -0,0 +1,77 @@ +package bsc + +import ( + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" +) + +func GetERC20Balance(mnemonic string, contractAddr common.Address) (*big.Int, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return nil, err + } + publicKey := privKey.PublicKey + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return nil, err + } + bal, err := ins.BalanceOf(nil, crypto.PubkeyToAddress(publicKey)) + if err != nil { + return nil, err + } else { + return bal, nil + } +} + +func GetERC20BalanceFromWalletAddress(walletAddress common.Address, contractAddr common.Address) (*big.Int, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return nil, err + } + bal, err := ins.BalanceOf(nil, walletAddress) + if err != nil { + return nil, err + } else { + return bal, nil + } +} + +func GetERC20BalanceInDecimalsFromWalletAddress(walletAddress common.Address, contractAddr common.Address) (*big.Float, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return nil, err + } + decimals, err := ins.Decimals(nil) + if err != nil { + return nil, err + } + decimalsCal := big.NewInt(0) + decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) + // amount.Mul(&amount, decimalsCal) + bal, err := ins.BalanceOf(nil, walletAddress) + if err != nil { + return nil, err + } + token := big.NewFloat(0).SetInt(big.NewInt(decimalsCal.Int64())) + balanceInDecimals := big.NewFloat(0).SetInt(bal) + balanceInDecimals.Quo(balanceInDecimals, token) + return balanceInDecimals, nil +} diff --git a/pkg/network/bsc/getErc721Bal.go b/pkg/network/bsc/getErc721Bal.go new file mode 100644 index 0000000..725c760 --- /dev/null +++ b/pkg/network/bsc/getErc721Bal.go @@ -0,0 +1,34 @@ +package bsc + +import ( + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" +) + +func GetERC721Balance(mnemonic string, contractAddr common.Address) (*big.Int, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return nil, err + } + publicKey := privKey.PublicKey + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, err + } + ins, err := generc721.NewErc721(contractAddr, client) + if err != nil { + return nil, err + } + bal, err := ins.BalanceOf(nil, crypto.PubkeyToAddress(publicKey)) + if err != nil { + return nil, err + } else { + return bal, nil + } +} diff --git a/pkg/network/bsc/getSignature.go b/pkg/network/bsc/getSignature.go new file mode 100644 index 0000000..3a05e9a --- /dev/null +++ b/pkg/network/bsc/getSignature.go @@ -0,0 +1,30 @@ +package bsc + +import ( + "fmt" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" +) + +func SignMessage(mnemonic string, message string) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + newMsg := fmt.Sprintf("\x19Ethereum Signed Message:\n%v%v", len(message), message) + + // keccak256 hash of the data + dataBytes := []byte(newMsg) + hashData := crypto.Keccak256Hash(dataBytes) + + signatureBytes, err := crypto.Sign(hashData.Bytes(), privKey) + if err != nil { + return "", err + } + + signature := hexutil.Encode(signatureBytes) + + return signature, nil +} diff --git a/pkg/network/bsc/setApprovalForAllErc721.go b/pkg/network/bsc/setApprovalForAllErc721.go new file mode 100644 index 0000000..a202e17 --- /dev/null +++ b/pkg/network/bsc/setApprovalForAllErc721.go @@ -0,0 +1,31 @@ +package bsc + +import ( + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func SetAprovalForAllErc721(mnemonic string, operatorAddr common.Address, contractAddr common.Address, approved bool) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + chainId, err := GetChainId() + if err != nil { + return "", err + } + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "setApprovalForAll", operatorAddr, &approved) + if err != nil { + return "", err + } + return tx.Hash().Hex(), nil + +} diff --git a/pkg/network/bsc/transfer.go b/pkg/network/bsc/transfer.go new file mode 100644 index 0000000..2fccdf4 --- /dev/null +++ b/pkg/network/bsc/transfer.go @@ -0,0 +1,73 @@ +package bsc + +import ( + "context" + "math/big" + + "github.com/TheLazarusNetwork/go-helpers/logo" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus/misc" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/ethereum/go-ethereum/params" +) + +func Transfer(mnemonic string, to common.Address, value big.Int) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + publicKey := privKey.PublicKey + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + nonce, err := client.PendingNonceAt(context.Background(), crypto.PubkeyToAddress(publicKey)) + if err != nil { + return "", err + } + + maxPriorityFeePerGas, err := client.SuggestGasTipCap(context.Background()) + if err != nil { + logo.Errorf("failed to suggestGasTipCap, error %s", err) + return "", err + } + chainId, err := GetChainId() + if err != nil { + return "", err + } + config := ¶ms.ChainConfig{ + ChainID: big.NewInt(int64(chainId)), + } + bn, _ := client.BlockNumber(context.Background()) + + bignumBn := big.NewInt(0).SetUint64(bn) + blk, _ := client.BlockByNumber(context.Background(), bignumBn) + baseFee := misc.CalcBaseFee(config, blk.Header()) + big2 := big.NewInt(2) + mulRes := big.NewInt(0).Mul(baseFee, big2) + maxFeePerGas := big.NewInt(0).Add(mulRes, maxPriorityFeePerGas) + tx := types.NewTx(&types.DynamicFeeTx{ + ChainID: big.NewInt(int64(chainId)), + Nonce: nonce, + GasFeeCap: maxFeePerGas, + GasTipCap: maxPriorityFeePerGas, + Gas: 21000, + To: &to, + Value: &value, + }) + types.SignTx(tx, types.NewLondonSigner(big.NewInt(int64(chainId))), privKey) + signedTx, err := types.SignTx(tx, types.NewLondonSigner(big.NewInt(int64(chainId))), privKey) + if err != nil { + return "", err + } + + err = client.SendTransaction(context.Background(), signedTx) + if err != nil { + return "", err + } + return signedTx.Hash().Hex(), nil +} \ No newline at end of file diff --git a/pkg/network/bsc/transferErc20.go b/pkg/network/bsc/transferErc20.go new file mode 100644 index 0000000..89f34f8 --- /dev/null +++ b/pkg/network/bsc/transferErc20.go @@ -0,0 +1,81 @@ +package bsc + +import ( + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func TransferERC20(mnemonic string, toAddress common.Address, contractAddr common.Address, amount big.Int) (string, error) { + // TODO: Ammount, check in goethbook guide + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return "", err + } + decimals, err := ins.Decimals(nil) + if err != nil { + return "", err + } + decimalsCal := big.NewInt(0) + decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) + amount.Mul(&amount, decimalsCal) + chainId, err := GetChainId() + if err != nil { + return "", err + } + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc20.Erc20MetaData.ABI, "transfer", toAddress, &amount) + if err != nil { + return "", err + } + return tx.Hash().Hex(), nil +} + +func TransferERC20AcceptFloat(mnemonic string, toAddress common.Address, contractAddr common.Address, amount float64) (string, error) { + // TODO: Ammount, check in goethbook guide + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return "", err + } + decimals, err := ins.Decimals(nil) + if err != nil { + return "", err + } + decimalsCal := big.NewInt(0) + decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) + // amount.Mul(&amount, decimalsCal) + var amountInInt64 = int64(amount * float64(10000)) + var amountInBigInt = decimalsCal.Mul(decimalsCal, big.NewInt(amountInInt64)) + amountInBigInt.Div(amountInBigInt, big.NewInt(10000)) + + chainId, err := GetChainId() + if err != nil { + return "", err + } + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc20.Erc20MetaData.ABI, "transfer", toAddress, &amountInBigInt) + if err != nil { + return "", err + } + return tx.Hash().Hex(), nil +} diff --git a/pkg/network/bsc/transferErc721.go b/pkg/network/bsc/transferErc721.go new file mode 100644 index 0000000..94cb7af --- /dev/null +++ b/pkg/network/bsc/transferErc721.go @@ -0,0 +1,36 @@ +package bsc + +import ( + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" +) + +func TransferERC721(mnemonic string, toAddress common.Address, contractAddr common.Address, tokenId big.Int) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + chainId, err := GetChainId() + if err != nil { + return "", err + } + publicKey := privKey.PublicKey + fromAddr := crypto.PubkeyToAddress(publicKey) + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "safeTransferFrom", fromAddr, toAddress, &tokenId) + if err != nil { + return "", err + } + return tx.Hash().Hex(), nil + +} diff --git a/pkg/network/bsc/types.go b/pkg/network/bsc/types.go new file mode 100644 index 0000000..49f127b --- /dev/null +++ b/pkg/network/bsc/types.go @@ -0,0 +1,8 @@ +package bsc + +import "math/big" + +type networkInfo struct { + Name string + ChainId *big.Int +} diff --git a/pkg/network/bsc/verifySignature.go b/pkg/network/bsc/verifySignature.go new file mode 100644 index 0000000..17a4579 --- /dev/null +++ b/pkg/network/bsc/verifySignature.go @@ -0,0 +1,46 @@ +package bsc + +import ( + "errors" + "fmt" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" +) + +var ( + ErrSignatureNotValid = errors.New("signature is not valid") +) + +func VerifySignature(mnemonic string, message string, signature string) (bool, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return false, err + } + walletAddrFromMnemonic := crypto.PubkeyToAddress(privKey.PublicKey) + + newMsg := fmt.Sprintf("\x19Ethereum Signed Message:\n%v%v", len(message), message) + newMsgHash := crypto.Keccak256Hash([]byte(newMsg)) + signatureInBytes, err := hexutil.Decode(signature) + if err != nil { + return false, err + } + if signatureInBytes[64] == 27 || signatureInBytes[64] == 28 { + signatureInBytes[64] -= 27 + } + pubKeyFromSignature, err := crypto.SigToPub(newMsgHash.Bytes(), signatureInBytes) + + if err != nil { + return false, err + } + + //Get address from public key + walletAddressFromSignature := crypto.PubkeyToAddress(*pubKeyFromSignature) + if walletAddrFromMnemonic.Hex() == walletAddressFromSignature.Hex() { + return true, nil + } else { + return false, nil + } + +} diff --git a/pkg/network/bsc/virtuacoinnft/burn.go b/pkg/network/bsc/virtuacoinnft/burn.go new file mode 100644 index 0000000..0ddae06 --- /dev/null +++ b/pkg/network/bsc/virtuacoinnft/burn.go @@ -0,0 +1,37 @@ +package virtuacoinnft + +import ( + "fmt" + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/virtuacoinnft" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func Burn(mnemonic string, contractAddr common.Address, tokenId big.Int) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, bsc.GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(bsc.GetRpcUrl()) + if err != nil { + return "", err + } + chainId, err := bsc.GetChainId() + if err != nil { + return "", err + } + + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, virtuacoinnft.VirtuacoinnftABI, "burn", &tokenId) + if err != nil { + err = fmt.Errorf("failed to send raw transaction: %w", err) + return "", err + } + return tx.Hash().Hex(), nil + +} diff --git a/pkg/network/bsc/virtuacoinnft/delegateassetcreation.go b/pkg/network/bsc/virtuacoinnft/delegateassetcreation.go new file mode 100644 index 0000000..ebfec2d --- /dev/null +++ b/pkg/network/bsc/virtuacoinnft/delegateassetcreation.go @@ -0,0 +1,41 @@ +package virtuacoinnft + +import ( + "fmt" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/virtuacoinnft" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func DelegateAssetCreation(walletAddress string, contractAddr common.Address, metadataURI string) (string, error) { + operatorPrivKey, err := wallet.GetWallet(envconfig.EnvVars.OPERATOR_MNEMONIC, bsc.GetPath()) + if err != nil { + err = fmt.Errorf("failed to get operator wallet from mnemonic: %w", err) + return "", err + } + + client, err := ethclient.Dial(bsc.GetRpcUrl()) + if err != nil { + err = fmt.Errorf("failed to dial rpc url: %w", err) + return "", err + } + chainId, err := bsc.GetChainId() + if err != nil { + return "", err + } + + creatorAddress := common.HexToAddress(walletAddress) + + tx, err := rawtransaction.SendRawTransaction(operatorPrivKey, *client, int64(chainId), 310000, contractAddr, virtuacoinnft.VirtuacoinnftABI, "delegateAssetCreation", creatorAddress, metadataURI) + if err != nil { + err = fmt.Errorf("failed to send raw transaction: %w", err) + return "", err + } + return tx.Hash().Hex(), nil + +} diff --git a/pkg/network/bsc/virtuacoinnft/grantrole.go b/pkg/network/bsc/virtuacoinnft/grantrole.go new file mode 100644 index 0000000..1855cd2 --- /dev/null +++ b/pkg/network/bsc/virtuacoinnft/grantrole.go @@ -0,0 +1,44 @@ +package virtuacoinnft + +import ( + "fmt" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/virtuacoinnft" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/bsc" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/ethclient" +) + +func GrantRole(roleId string, walletAddress string, contractAddr common.Address) (string, error) { + operatorPrivKey, err := wallet.GetWallet(envconfig.EnvVars.OPERATOR_MNEMONIC, bsc.GetPath()) + if err != nil { + err = fmt.Errorf("failed to get operator wallet from mnemonic: %w", err) + return "", err + } + + client, err := ethclient.Dial(bsc.GetRpcUrl()) + if err != nil { + err = fmt.Errorf("failed to dial rpc url: %w", err) + return "", err + } + chainId, err := bsc.GetChainId() + if err != nil { + return "", err + } + + roleIdBytesSlice, _ := hexutil.Decode(roleId) + var roleIdBytes [32]byte + copy(roleIdBytes[:], roleIdBytesSlice) + creatorAddress := common.HexToAddress(walletAddress) + + tx, err := rawtransaction.SendRawTransaction(operatorPrivKey, *client, int64(chainId), 310000, contractAddr, virtuacoinnft.VirtuacoinnftABI, "grantRole", roleIdBytes, creatorAddress) + if err != nil { + err = fmt.Errorf("failed to send raw transaction: %w", err) + return "", err + } + return tx.Hash().Hex(), nil +} diff --git a/pkg/network/ethereum/ethereum.go b/pkg/network/ethereum/ethereum.go index 36bfed1..fac0818 100644 --- a/pkg/network/ethereum/ethereum.go +++ b/pkg/network/ethereum/ethereum.go @@ -2,14 +2,20 @@ package ethereum import ( "context" + "crypto/ecdsa" + "errors" + "log" "math/big" + "strings" "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - "github.com/TheLazarusNetwork/superiad/generated/generc20" - "github.com/TheLazarusNetwork/superiad/generated/generc721" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" - rawtrasaction "github.com/TheLazarusNetwork/superiad/pkg/wallet/rawtransaction" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + rawtrasaction "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/core/types" @@ -19,7 +25,7 @@ import ( ) func GetChainId() (int, error) { - return 1, nil + return envconfig.EnvVars.CHAIN_ID_ETHEREUM, nil } func GetPath() string { @@ -128,36 +134,111 @@ func Transfer(mnemonic string, to common.Address, value big.Int) (string, error) return signedTx.Hash().Hex(), nil } -func TransferERC20(mnemonic string, toAddress common.Address, contractAddr common.Address, amount big.Int) (string, error) { - // TODO: Ammount, check in goethbook guide - privKey, err := wallet.GetWallet(mnemonic, GetPath()) +// func TransferERC20(mnemonic string, toAddress common.Address, contractAddr common.Address, amount big.Int) (string, error) { +// // TODO: Ammount, check in goethbook guide +// privKey, err := wallet.GetWallet(mnemonic, GetPath()) +// if err != nil { +// return "", err +// } + +// client, err := ethclient.Dial(GetRpcUrl()) +// if err != nil { +// return "", err +// } +// ins, err := generc20.NewErc20(contractAddr, client) +// if err != nil { +// return "", err +// } +// decimals, err := ins.Decimals(nil) +// if err != nil { +// return "", err +// } +// decimalsCal := big.NewInt(0) +// decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) +// amount.Mul(&amount, decimalsCal) +// chainId, err := GetChainId() +// if err != nil { +// return "", err +// } +// tx, err := rawtrasaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc20.Erc20MetaData.ABI, "transfer", toAddress, &amount) +// if err != nil { +// return "", err +// } +// return tx.Hash().Hex(), nil +// } + +// ERC20 ABI (same as in erc20.go) +const erc20ABI = `[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"inputs":[{"name":"_initialAmount","type":"uint256"},{"name":"_tokenName","type":"string"},{"name":"_decimalUnits","type":"uint8"},{"name":"_tokenSymbol","type":"string"}],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]` + +func TransferERC20(mnemonic string, toAddress common.Address, contractAddr common.Address, amount *big.Int) (string, error) { + privateKeyHex, err := wallet.GetWallet(mnemonic, GetPath()) if err != nil { return "", err } client, err := ethclient.Dial(GetRpcUrl()) if err != nil { + log.Printf("Failed to connect to Ethereum client: %v", err) return "", err } - ins, err := generc20.NewErc20(contractAddr, client) + + // privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(privateKeyHex, "0x")) + // if err != nil { + // log.Printf("Invalid private key: %v", err) + // return "", err + // } + + publicKey := privateKeyHex.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Printf("Error casting public key to ECDSA") + return "", errors.New("error casting public key to ECDSA") + } + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) if err != nil { + log.Printf("Failed to retrieve nonce: %v", err) return "", err } - decimals, err := ins.Decimals(nil) + + gasPrice, err := client.SuggestGasPrice(context.Background()) if err != nil { + log.Printf("Failed to suggest gas price: %v", err) return "", err } - decimalsCal := big.NewInt(0) - decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) - amount.Mul(&amount, decimalsCal) - chainId, err := GetChainId() + + chainID, err := client.NetworkID(context.Background()) if err != nil { + log.Printf("Failed to get chain ID: %v", err) return "", err } - tx, err := rawtrasaction.SendRawTrasac(privKey, *client, int64(chainId), 310000, contractAddr, generc20.Erc20MetaData.ABI, "transfer", toAddress, &amount) + + auth, err := bind.NewKeyedTransactorWithChainID(privateKeyHex, chainID) if err != nil { + log.Printf("Failed to create transactor: %v", err) return "", err } + + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(500000) // in units + auth.GasPrice = gasPrice + + parsedABI, err := abi.JSON(strings.NewReader(erc20ABI)) + if err != nil { + log.Printf("Failed to parse ABI: %v", err) + return "", err + } + instance := bind.NewBoundContract(contractAddr, parsedABI, client, client, client) + + tx, err := instance.Transact(auth, "transfer", toAddress, amount) + if err != nil { + log.Printf("Failed to send transaction: %v", err) + return "", err + } + + log.Printf("Transaction sent: %s", tx.Hash().Hex()) return tx.Hash().Hex(), nil } @@ -177,7 +258,7 @@ func TransferERC721(mnemonic string, toAddress common.Address, contractAddr comm } publicKey := privKey.PublicKey fromAddr := crypto.PubkeyToAddress(publicKey) - tx, err := rawtrasaction.SendRawTrasac(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "safeTransferFrom", fromAddr, toAddress, &tokenId) + tx, err := rawtrasaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "safeTransferFrom", fromAddr, toAddress, &tokenId) if err != nil { return "", err } @@ -205,3 +286,29 @@ func GetWalletAddres(mnemonic string) (string, error) { return walletAddr.String(), nil } + +func GetERC20BalanceInDecimalsFromWalletAddress(walletAddress common.Address, contractAddr common.Address) (*big.Float, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return nil, err + } + decimals, err := ins.Decimals(nil) + if err != nil { + return nil, err + } + decimalsCal := big.NewInt(0) + decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) + // amount.Mul(&amount, decimalsCal) + bal, err := ins.BalanceOf(nil, walletAddress) + if err != nil { + return nil, err + } + token := big.NewFloat(0).SetInt(big.NewInt(decimalsCal.Int64())) + balanceInDecimals := big.NewFloat(0).SetInt(bal) + balanceInDecimals.Quo(balanceInDecimals, token) + return balanceInDecimals, nil +} diff --git a/pkg/network/polygon/approveErc721.go b/pkg/network/polygon/approveErc721.go index e9e0483..75f0c75 100644 --- a/pkg/network/polygon/approveErc721.go +++ b/pkg/network/polygon/approveErc721.go @@ -3,9 +3,9 @@ package polygon import ( "math/big" - "github.com/TheLazarusNetwork/superiad/generated/generc721" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" - rawtrasaction "github.com/TheLazarusNetwork/superiad/pkg/wallet/rawtransaction" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" ) @@ -24,7 +24,7 @@ func ApproveERC721(mnemonic string, toAddress common.Address, contractAddr commo if err != nil { return "", err } - tx, err := rawtrasaction.SendRawTrasac(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "approve", toAddress, &tokenId) + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "approve", toAddress, &tokenId) if err != nil { return "", err } diff --git a/pkg/network/polygon/burnErc721.go b/pkg/network/polygon/burnErc721.go new file mode 100644 index 0000000..ce1ae91 --- /dev/null +++ b/pkg/network/polygon/burnErc721.go @@ -0,0 +1,32 @@ +package polygon + +import ( + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func BurnERC721(mnemonic string, contractAddr common.Address, tokenId big.Int) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return "", err + } + chainId, err := GetChainId() + if err != nil { + return "", err + } + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "burn", &tokenId) + if err != nil { + return "", err + } + return tx.Hash().Hex(), nil +} diff --git a/pkg/network/polygon/getErc20Bal.go b/pkg/network/polygon/getErc20Bal.go index 4c761c5..81161c6 100644 --- a/pkg/network/polygon/getErc20Bal.go +++ b/pkg/network/polygon/getErc20Bal.go @@ -3,8 +3,8 @@ package polygon import ( "math/big" - "github.com/TheLazarusNetwork/superiad/generated/generc20" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc20" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" @@ -32,3 +32,46 @@ func GetERC20Balance(mnemonic string, contractAddr common.Address) (*big.Int, er return bal, nil } } + +func GetERC20BalanceFromWalletAddress(walletAddress common.Address, contractAddr common.Address) (*big.Int, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return nil, err + } + bal, err := ins.BalanceOf(nil, walletAddress) + if err != nil { + return nil, err + } else { + return bal, nil + } +} + +func GetERC20BalanceInDecimalsFromWalletAddress(walletAddress common.Address, contractAddr common.Address) (*big.Float, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, err + } + ins, err := generc20.NewErc20(contractAddr, client) + if err != nil { + return nil, err + } + decimals, err := ins.Decimals(nil) + if err != nil { + return nil, err + } + decimalsCal := big.NewInt(0) + decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) + // amount.Mul(&amount, decimalsCal) + bal, err := ins.BalanceOf(nil, walletAddress) + if err != nil { + return nil, err + } + token := big.NewFloat(0).SetInt(big.NewInt(decimalsCal.Int64())) + balanceInDecimals := big.NewFloat(0).SetInt(bal) + balanceInDecimals.Quo(balanceInDecimals, token) + return balanceInDecimals, nil +} diff --git a/pkg/network/polygon/getErc721Bal.go b/pkg/network/polygon/getErc721Bal.go index 68378e1..aef2c18 100644 --- a/pkg/network/polygon/getErc721Bal.go +++ b/pkg/network/polygon/getErc721Bal.go @@ -3,8 +3,8 @@ package polygon import ( "math/big" - "github.com/TheLazarusNetwork/superiad/generated/generc721" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" diff --git a/pkg/network/polygon/getErc721IsOwner.go b/pkg/network/polygon/getErc721IsOwner.go deleted file mode 100644 index 72ce2b0..0000000 --- a/pkg/network/polygon/getErc721IsOwner.go +++ /dev/null @@ -1,36 +0,0 @@ -package polygon - -import ( - "math/big" - - "github.com/TheLazarusNetwork/superiad/generated/generc721" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethclient" -) - -func ERC721IsOwner(mnemonic string, contractAddr common.Address, tokenId *big.Int) (bool, error) { - privKey, err := wallet.GetWallet(mnemonic, GetPath()) - if err != nil { - return false, err - } - publicKey := privKey.PublicKey - client, err := ethclient.Dial(GetRpcUrl()) - if err != nil { - return false, err - } - - ins, err := generc721.NewErc721(contractAddr, client) - if err != nil { - return false, err - } - ownerAddr, err := ins.OwnerOf(nil, tokenId) - if err != nil { - return false, err - } else if ownerAddr.String() == crypto.PubkeyToAddress(publicKey).String() { - return true, nil - } else { - return false, nil - } -} diff --git a/pkg/network/polygon/getSignature.go b/pkg/network/polygon/getSignature.go index 4e8eadc..559acc9 100644 --- a/pkg/network/polygon/getSignature.go +++ b/pkg/network/polygon/getSignature.go @@ -3,7 +3,7 @@ package polygon import ( "fmt" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" ) diff --git a/pkg/network/polygon/polygon.go b/pkg/network/polygon/polygon.go index 56c2e8e..229daf8 100644 --- a/pkg/network/polygon/polygon.go +++ b/pkg/network/polygon/polygon.go @@ -2,17 +2,19 @@ package polygon import ( "context" + "encoding/hex" "fmt" "math/big" - "github.com/TheLazarusNetwork/superiad/config/envconfig" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" ) func GetChainId() (int, error) { - return 80001, nil + return envconfig.EnvVars.CHAIN_ID_POLYGON, nil } func GetPath() string { @@ -40,6 +42,34 @@ func GetBalance(mnemonic string) (*big.Int, error) { return bal, nil } +func GetBalanceFromWalletAddress(walletAddress string) (*big.Int, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, fmt.Errorf("failed to dial rpc client :%w", err) + } + bal, err := client.BalanceAt(context.Background(), common.HexToAddress(walletAddress), nil) + if err != nil { + return nil, fmt.Errorf("failed to call BalanceAt :%w", err) + } + return bal, nil +} + +func GetBalanceInDecimalsFromWalletAddress(walletAddress string) (*big.Float, error) { + client, err := ethclient.Dial(GetRpcUrl()) + if err != nil { + return nil, fmt.Errorf("failed to dial rpc client :%w", err) + } + bal, err := client.BalanceAt(context.Background(), common.HexToAddress(walletAddress), nil) + if err != nil { + return nil, fmt.Errorf("failed to call BalanceAt :%w", err) + } + + ether := big.NewFloat(0).SetInt(big.NewInt(1000000000000000000)) + balanceInDecimals := big.NewFloat(0).SetInt(bal) + balanceInDecimals.Quo(balanceInDecimals, ether) + return balanceInDecimals, nil +} + func GetNetworkInfo() (*networkInfo, error) { chainId, err := GetChainId() if err != nil { @@ -60,3 +90,13 @@ func GetWalletAddres(mnemonic string) (string, error) { return walletAddr.String(), nil } + +func GetWalletPrivateKey(mnemonic string) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, GetPath()) + if err != nil { + return "", err + } + privateKeyBytes := crypto.FromECDSA(privKey) + + return hex.EncodeToString(privateKeyBytes[2:]), nil +} diff --git a/pkg/network/polygon/setApprovalForAllErc721.go b/pkg/network/polygon/setApprovalForAllErc721.go index 69f5952..a641df4 100644 --- a/pkg/network/polygon/setApprovalForAllErc721.go +++ b/pkg/network/polygon/setApprovalForAllErc721.go @@ -1,9 +1,9 @@ package polygon import ( - "github.com/TheLazarusNetwork/superiad/generated/generc721" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" - rawtrasaction "github.com/TheLazarusNetwork/superiad/pkg/wallet/rawtransaction" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" ) @@ -22,7 +22,7 @@ func SetAprovalForAllErc721(mnemonic string, operatorAddr common.Address, contra if err != nil { return "", err } - tx, err := rawtrasaction.SendRawTrasac(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "setApprovalForAll", operatorAddr, &approved) + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "setApprovalForAll", operatorAddr, &approved) if err != nil { return "", err } diff --git a/pkg/network/polygon/transfer.go b/pkg/network/polygon/transfer.go index 692907b..d764bae 100644 --- a/pkg/network/polygon/transfer.go +++ b/pkg/network/polygon/transfer.go @@ -5,7 +5,7 @@ import ( "math/big" "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/core/types" @@ -70,4 +70,4 @@ func Transfer(mnemonic string, to common.Address, value big.Int) (string, error) return "", err } return signedTx.Hash().Hex(), nil -} +} \ No newline at end of file diff --git a/pkg/network/polygon/transferErc20.go b/pkg/network/polygon/transferErc20.go index d624ece..7303fc2 100644 --- a/pkg/network/polygon/transferErc20.go +++ b/pkg/network/polygon/transferErc20.go @@ -1,44 +1,92 @@ package polygon import ( + "context" + "crypto/ecdsa" + "errors" + "log" "math/big" + "strings" - "github.com/TheLazarusNetwork/superiad/generated/generc20" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" - rawtrasaction "github.com/TheLazarusNetwork/superiad/pkg/wallet/rawtransaction" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" ) -func TransferERC20(mnemonic string, toAddress common.Address, contractAddr common.Address, amount big.Int) (string, error) { - // TODO: Ammount, check in goethbook guide - privKey, err := wallet.GetWallet(mnemonic, GetPath()) +// ERC20 ABI (same as in erc20.go) +const erc20ABI = `[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"inputs":[{"name":"_initialAmount","type":"uint256"},{"name":"_tokenName","type":"string"},{"name":"_decimalUnits","type":"uint8"},{"name":"_tokenSymbol","type":"string"}],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]` + +func TransferERC20(mnemonic string, toAddress common.Address, contractAddr common.Address, amount *big.Int) (string, error) { + privateKeyHex, err := wallet.GetWallet(mnemonic, GetPath()) if err != nil { return "", err } client, err := ethclient.Dial(GetRpcUrl()) if err != nil { + log.Printf("Failed to connect to Ethereum client: %v", err) + return "", err + } + + // privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(privateKeyHex, "0x")) + // if err != nil { + // log.Printf("Invalid private key: %v", err) + // return "", err + // } + + publicKey := privateKeyHex.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Printf("Error casting public key to ECDSA") + return "", errors.New("error casting public key to ECDSA") + } + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Printf("Failed to retrieve nonce: %v", err) + return "", err + } + + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + log.Printf("Failed to suggest gas price: %v", err) return "", err } - ins, err := generc20.NewErc20(contractAddr, client) + + chainID, err := client.NetworkID(context.Background()) if err != nil { + log.Printf("Failed to get chain ID: %v", err) return "", err } - decimals, err := ins.Decimals(nil) + + auth, err := bind.NewKeyedTransactorWithChainID(privateKeyHex, chainID) if err != nil { + log.Printf("Failed to create transactor: %v", err) return "", err } - decimalsCal := big.NewInt(0) - decimalsCal.Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil) - amount.Mul(&amount, decimalsCal) - chainId, err := GetChainId() + + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(500000) // in units + auth.GasPrice = gasPrice + + parsedABI, err := abi.JSON(strings.NewReader(erc20ABI)) if err != nil { + log.Printf("Failed to parse ABI: %v", err) return "", err } - tx, err := rawtrasaction.SendRawTrasac(privKey, *client, int64(chainId), 310000, contractAddr, generc20.Erc20MetaData.ABI, "transfer", toAddress, &amount) + instance := bind.NewBoundContract(contractAddr, parsedABI, client, client, client) + + tx, err := instance.Transact(auth, "transfer", toAddress, amount) if err != nil { + log.Printf("Failed to send transaction: %v", err) return "", err } + + log.Printf("Transaction sent: %s", tx.Hash().Hex()) return tx.Hash().Hex(), nil } diff --git a/pkg/network/polygon/transferErc721.go b/pkg/network/polygon/transferErc721.go index 6d9e16e..f319002 100644 --- a/pkg/network/polygon/transferErc721.go +++ b/pkg/network/polygon/transferErc721.go @@ -3,9 +3,9 @@ package polygon import ( "math/big" - "github.com/TheLazarusNetwork/superiad/generated/generc721" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" - rawtrasaction "github.com/TheLazarusNetwork/superiad/pkg/wallet/rawtransaction" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/generc721" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" @@ -27,7 +27,7 @@ func TransferERC721(mnemonic string, toAddress common.Address, contractAddr comm } publicKey := privKey.PublicKey fromAddr := crypto.PubkeyToAddress(publicKey) - tx, err := rawtrasaction.SendRawTrasac(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "safeTransferFrom", fromAddr, toAddress, &tokenId) + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, generc721.Erc721MetaData.ABI, "safeTransferFrom", fromAddr, toAddress, &tokenId) if err != nil { return "", err } diff --git a/pkg/network/polygon/verifySignature.go b/pkg/network/polygon/verifySignature.go index b8d130c..71bc860 100644 --- a/pkg/network/polygon/verifySignature.go +++ b/pkg/network/polygon/verifySignature.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/TheLazarusNetwork/superiad/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" ) diff --git a/pkg/network/polygon/virtuacoinnft/burn.go b/pkg/network/polygon/virtuacoinnft/burn.go new file mode 100644 index 0000000..56d6ba4 --- /dev/null +++ b/pkg/network/polygon/virtuacoinnft/burn.go @@ -0,0 +1,37 @@ +package virtuacoinnft + +import ( + "fmt" + "math/big" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/virtuacoinnft" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func Burn(mnemonic string, contractAddr common.Address, tokenId big.Int) (string, error) { + privKey, err := wallet.GetWallet(mnemonic, polygon.GetPath()) + if err != nil { + return "", err + } + + client, err := ethclient.Dial(polygon.GetRpcUrl()) + if err != nil { + return "", err + } + chainId, err := polygon.GetChainId() + if err != nil { + return "", err + } + + tx, err := rawtransaction.SendRawTransaction(privKey, *client, int64(chainId), 310000, contractAddr, virtuacoinnft.VirtuacoinnftABI, "burn", &tokenId) + if err != nil { + err = fmt.Errorf("failed to send raw transaction: %w", err) + return "", err + } + return tx.Hash().Hex(), nil + +} diff --git a/pkg/network/polygon/virtuacoinnft/delegateassetcreation.go b/pkg/network/polygon/virtuacoinnft/delegateassetcreation.go new file mode 100644 index 0000000..b6d4573 --- /dev/null +++ b/pkg/network/polygon/virtuacoinnft/delegateassetcreation.go @@ -0,0 +1,41 @@ +package virtuacoinnft + +import ( + "fmt" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/virtuacoinnft" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" +) + +func DelegateAssetCreation(walletAddress string, contractAddr common.Address, metadataURI string) (string, error) { + operatorPrivKey, err := wallet.GetWallet(envconfig.EnvVars.OPERATOR_MNEMONIC, polygon.GetPath()) + if err != nil { + err = fmt.Errorf("failed to get operator wallet from mnemonic: %w", err) + return "", err + } + + client, err := ethclient.Dial(polygon.GetRpcUrl()) + if err != nil { + err = fmt.Errorf("failed to dial rpc url: %w", err) + return "", err + } + chainId, err := polygon.GetChainId() + if err != nil { + return "", err + } + + creatorAddress := common.HexToAddress(walletAddress) + + tx, err := rawtransaction.SendRawTransaction(operatorPrivKey, *client, int64(chainId), 310000, contractAddr, virtuacoinnft.VirtuacoinnftABI, "delegateAssetCreation", creatorAddress, metadataURI) + if err != nil { + err = fmt.Errorf("failed to send raw transaction: %w", err) + return "", err + } + return tx.Hash().Hex(), nil + +} diff --git a/pkg/network/polygon/virtuacoinnft/grantrole.go b/pkg/network/polygon/virtuacoinnft/grantrole.go new file mode 100644 index 0000000..470732d --- /dev/null +++ b/pkg/network/polygon/virtuacoinnft/grantrole.go @@ -0,0 +1,44 @@ +package virtuacoinnft + +import ( + "fmt" + + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/config/envconfig" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/generated/virtuacoinnft" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/network/polygon" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet" + "github.com/VirtuaTechnologies/VirtuaCoin_Wallet/pkg/wallet/rawtransaction" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/ethclient" +) + +func GrantRole(roleId string, walletAddress string, contractAddr common.Address) (string, error) { + operatorPrivKey, err := wallet.GetWallet(envconfig.EnvVars.OPERATOR_MNEMONIC, polygon.GetPath()) + if err != nil { + err = fmt.Errorf("failed to get operator wallet from mnemonic: %w", err) + return "", err + } + + client, err := ethclient.Dial(polygon.GetRpcUrl()) + if err != nil { + err = fmt.Errorf("failed to dial rpc url: %w", err) + return "", err + } + chainId, err := polygon.GetChainId() + if err != nil { + return "", err + } + + roleIdBytesSlice, _ := hexutil.Decode(roleId) + var roleIdBytes [32]byte + copy(roleIdBytes[:], roleIdBytesSlice) + creatorAddress := common.HexToAddress(walletAddress) + + tx, err := rawtransaction.SendRawTransaction(operatorPrivKey, *client, int64(chainId), 310000, contractAddr, virtuacoinnft.VirtuacoinnftABI, "grantRole", roleIdBytes, creatorAddress) + if err != nil { + err = fmt.Errorf("failed to send raw transaction: %w", err) + return "", err + } + return tx.Hash().Hex(), nil +} diff --git a/pkg/store/store.go b/pkg/store/store.go index fc48081..fa84679 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -2,7 +2,7 @@ package store import ( - "gorm.io/gorm" + "github.com/go-redis/redis/v8" ) -var DB *gorm.DB +var RDS *redis.Client diff --git a/pkg/testingcommon/db.go b/pkg/testingcommon/db.go deleted file mode 100644 index 6c49f06..0000000 --- a/pkg/testingcommon/db.go +++ /dev/null @@ -1,72 +0,0 @@ -package testingcommon - -import ( - "fmt" - - "github.com/TheLazarusNetwork/go-helpers/logo" - "github.com/TheLazarusNetwork/superiad/pkg/store" - "gorm.io/gorm" -) - -// Referred from https://medium.com/@jarifibrahim/using-gorm-hooks-to-clean-up-test-fixtures-in-golang-99b0fcb04354 -func DeleteCreatedEntities() func() { - db := store.DB - type entity struct { - table string - keyname string - key interface{} - } - var entries []entity - hookName := "cleanupHook" - - db.Callback().Create().After("gorm:create").Register(hookName, func(tx *gorm.DB) { - statement := tx.Statement.Statement - schema := tx.Statement.Schema - - if len(schema.PrimaryFields) == 0 { - return - } - - primaryFieldKey := "" - primaryFieldIndex := 0 - for i, v := range schema.Fields { - if v.PrimaryKey { - primaryFieldKey = v.DBName - primaryFieldIndex = i - break - } - } - - primaryFieldValue := statement.Vars[primaryFieldIndex] - - fmt.Printf("Inserted entities of %s with %s=%v\n", statement.Table, primaryFieldKey, primaryFieldValue) - - entries = append(entries, entity{table: statement.Table, keyname: primaryFieldKey, key: primaryFieldValue}) - }) - return func() { - // Remove the hook once we're done - defer db.Callback().Create().Remove(hookName) - - for i := len(entries) - 1; i >= 0; i-- { - entry := entries[i] - - var deleteValue string - switch v := entry.key.(type) { - case int: - deleteValue = fmt.Sprint(v) - - case string: - deleteValue = fmt.Sprintf("'%v'", v) - - default: - logo.Fatal("not implemented") - } - - q := fmt.Sprintf(`DELETE FROM %v WHERE %v=%v`, entry.table, entry.keyname, deleteValue) - if err := db.Exec(q).Error; err != nil { - logo.Warnf("failed to exec query: %s, in clean up hook, %s", q, err) - } - } - - } -} diff --git a/pkg/wallet/mnemonic.go b/pkg/wallet/mnemonic.go index 65e532e..612f43a 100644 --- a/pkg/wallet/mnemonic.go +++ b/pkg/wallet/mnemonic.go @@ -66,3 +66,47 @@ func GetWallet(mnemonic string, path string) (*ecdsa.PrivateKey, error) { privateKey := btcecPrivKey.ToECDSA() return privateKey, nil } + +func GetETHPrivateKey(mnemonic string, path string) (*ecdsa.PrivateKey, error) { + // Generate a Bip32 HD wallet for the mnemonic and a user supplied password + seed := bip39.NewSeed(mnemonic, "") + // Generate a new master node using the seed. + var masterKey *hdkeychain.ExtendedKey + var err error + paths := strings.Split(path, "/") + for _, v := range paths { + if v == "m" { + masterKey, err = hdkeychain.NewMaster(seed, &chaincfg.MainNetParams) + if err != nil { + return nil, err + } + continue + } + if strings.Contains(v, "H") { + hSplit, err := strconv.Atoi(strings.TrimSuffix(v, "H")) + if err != nil { + return nil, err + } + masterKey, err = masterKey.Derive(uint32(hdkeychain.HardenedKeyStart + hSplit)) + if err != nil { + return nil, err + } + } else { + res, err := strconv.Atoi(v) + if err != nil { + return nil, err + } + masterKey, err = masterKey.Derive(uint32((res))) + if err != nil { + return nil, err + } + } + } + + btcecPrivKey, err := masterKey.ECPrivKey() + if err != nil { + return nil, err + } + privateKey := btcecPrivKey.ToECDSA() + return privateKey, nil +} diff --git a/pkg/wallet/rawtransaction/rawtransaction.go b/pkg/wallet/rawtransaction/rawtransaction.go index 0991c17..e108746 100644 --- a/pkg/wallet/rawtransaction/rawtransaction.go +++ b/pkg/wallet/rawtransaction/rawtransaction.go @@ -1,8 +1,9 @@ -package rawtrasaction +package rawtransaction import ( "context" "crypto/ecdsa" + "fmt" "math/big" "strings" @@ -16,8 +17,8 @@ import ( "github.com/ethereum/go-ethereum/params" ) -func SendRawTrasac(privateKey *ecdsa.PrivateKey, client ethclient.Client, chainId int64, gas uint64, contractAddress common.Address, abiS string, method string, args ...interface{}) (*types.Transaction, error) { - +func SendRawTransaction(privateKey *ecdsa.PrivateKey, client ethclient.Client, chainId int64, gas uint64, contractAddress common.Address, abiS string, method string, args ...interface{}) (*types.Transaction, error) { + // Change this line abiP, err := abi.JSON(strings.NewReader(abiS)) if err != nil { logo.Errorf("failed to parse JSON abi, error %s", err) @@ -53,7 +54,10 @@ func SendRawTrasac(privateKey *ecdsa.PrivateKey, client ethclient.Client, chainI bn, _ := client.BlockNumber(context.Background()) bignumBn := big.NewInt(0).SetUint64(bn) - blk, _ := client.BlockByNumber(context.Background(), bignumBn) + blk, err := client.BlockByNumber(context.Background(), bignumBn) + if err != nil { + fmt.Println("error idhar :", err) + } baseFee := misc.CalcBaseFee(config, blk.Header()) big2 := big.NewInt(2) mulRes := big.NewInt(0).Mul(baseFee, big2) diff --git a/sample.env b/sample.env index 883abd5..4520ebd 100644 --- a/sample.env +++ b/sample.env @@ -1,12 +1,16 @@ GIN_MODE=debug -DB_HOST=localhost -DB_USERNAME=superiad -DB_PASSWORD=superiad -DB_NAME=superiad -DB_PORT=5432 +APP_ENVIRONMENT=DEV APP_PORT=3000 +REDIS_HOST= +REDIS_PORT= +REDIS_PASSWORD= +REDIS_DB=Superiad ALLOWED_ORIGIN="*" NETWORK_RPC_URL_ETHEREUM=https://eth-mainnet.public.blastapi.io NETWORK_RPC_URL_POLYGON=https://rpc-mumbai.matic.today -TOKEN=aa -APP_ENVIRONMENT=DEV \ No newline at end of file +NETWORK_RPC_URL_BSC= +TOKEN=0xE20b193763520Ea981036586599AC0cFB305400F +OPERATOR_MNEMONIC= +VIRTUACOINNFT_CONTRACT_ADDRESS=0xf3CF865a944BfA6312797E05a31a4083613D5085 +CHAIN_ID_POLYGON=80001 +CHAIN_ID_BSC=56 \ No newline at end of file