diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b444581 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..b079d93 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,70 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [main] + pull_request: + # The branches below must be a subset of the branches above + branches: [main] + schedule: + - cron: "44 11 * * 4" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["go"] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + queries: security-extended + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml new file mode 100644 index 0000000..406344b --- /dev/null +++ b/.github/workflows/lint-and-tests.yml @@ -0,0 +1,32 @@ +name: Lint + +on: + push: + branches: + - main + pull_request: + +env: + GO_VERSION: "1.21.7" + +jobs: + lint: + name: Lint + runs-on: ubuntu-20.04 + steps: + - uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.56.2 + working-directory: . + args: --timeout 5m + - name: Install license check + run: go install github.com/google/addlicense@v1.0.0 + - name: Check license + run: addlicense -f ./LICENSE.header -check -v ./**/*.go + #run: addlicense -f ./LICENSE.header -check -v ./**/*.go ./**/**/*.go ./**/**/**/*.go ./**/**/**/**/*.go + diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..3a2bc02 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,115 @@ +# https://golangci-lint.run/usage/configuration/ +run: + go: "1.21.7" + timeout: 10m + +issues: + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + # skip auto-generated files. + exclude-files: + - ".*\\.pb\\.go$" + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + enable: + - asciicheck + - depguard + - errcheck + - errorlint + - exportloopref + - goconst + - gocritic + - gofmt + - gofumpt + - goimports + - revive + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - nolintlint + - prealloc + - stylecheck + - unconvert + - unparam + - unused + - unconvert + - whitespace + - staticcheck + # - structcheck + # - lll + # - gomnd + # - goprintffuncname + # - interfacer + # - typecheck + # - goerr113 + # - noctx + +linters-settings: + errorlint: + # Check for plain type assertions and type switches. + asserts: false + # Check for plain error comparisons. + comparison: false + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr + - name: bool-literal-in-expr + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return + - name: early-return + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines + - name: empty-lines + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag + - name: struct-tag + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming + - name: unexported-naming + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error + - name: unhandled-error + disabled: false + arguments: + - "fmt.Fprint" + - "fmt.Fprintf" + - "fmt.Print" + - "fmt.Printf" + - "fmt.Fprintln" + - "fmt.Println" + - "rand.Read" + - "sb.WriteString" + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter + - name: unused-parameter + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver + - name: unused-receiver + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break + - name: useless-break + disabled: false + staticcheck: + # https://staticcheck.io/docs/options#checks + checks: + - "all" + - "-SA6002" # argument should be pointer-like to avoid allocation, for sync.Pool + - "-SA1019" # deprecated packages e.g., golang.org/x/crypto/ripemd160 + # https://golangci-lint.run/usage/linters#gosec + gosec: + excludes: + - G107 # https://securego.io/docs/rules/g107.html + - G204 + depguard: + rules: + packages: + deny: + - pkg: "io/ioutil" + desc: io/ioutil is deprecated. Use package io or os instead. + - pkg: "github.com/stretchr/testify/assert" + desc: github.com/stretchr/testify/require should be used instead. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dc33b08 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2022, Ava Labs, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSE.header b/LICENSE.header new file mode 100644 index 0000000..99525ca --- /dev/null +++ b/LICENSE.header @@ -0,0 +1,2 @@ +Copyright (C) 2022, Ava Labs, Inc. All rights reserved. +See the file LICENSE for licensing terms. \ No newline at end of file diff --git a/avalanche/avalanche.go b/avalanche/avalanche.go index e90aee4..e6ed8bf 100644 --- a/avalanche/avalanche.go +++ b/avalanche/avalanche.go @@ -18,4 +18,4 @@ func New() *Client { Logger: DefaultLeveledLogger, } return client -} +} \ No newline at end of file diff --git a/avalanche/network.go b/avalanche/network.go index 3c7a775..76f09df 100644 --- a/avalanche/network.go +++ b/avalanche/network.go @@ -11,6 +11,4 @@ type Network struct { ID uint32 Endpoint string - - ClusterName string } diff --git a/multisig/multisig.go b/multisig/multisig.go new file mode 100644 index 0000000..a7316b5 --- /dev/null +++ b/multisig/multisig.go @@ -0,0 +1,82 @@ +// Copyright (C) 2022, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. +package multisig + +import ( + "github.com/ava-labs/avalanche-tooling-sdk-go/network" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/vms/platformvm/txs" + "github.com/ava-labs/avalanchego/wallet/subnet/primary" +) + +type PChainTxKind int + +const ( + Invalid = iota + CreateBlockchain + TransferSubnetOwnership +) + +type PChainMultisig struct { + _ *txs.Tx +} + +func New(_ *txs.Tx) *PChainMultisig { + return nil +} + +func (*PChainMultisig) ToBytes() ([]byte, error) { + return nil, nil +} + +func (*PChainMultisig) FromBytes(_ []byte) error { + return nil +} + +func (*PChainMultisig) ToFile(_ string) error { + return nil +} + +func (*PChainMultisig) FromFile(_ string) error { + return nil +} + +func (*PChainMultisig) Sign(_ *primary.Wallet) error { + return nil +} + +func (*PChainMultisig) Commit() error { + return nil +} + +func (*PChainMultisig) IsReadyToCommit() error { + return nil +} + +func (*PChainMultisig) GetRemainingSigners() ([]ids.ID, error) { + return nil, nil +} + +func (*PChainMultisig) GetAuthSigners() ([]ids.ID, error) { + return nil, nil +} + +func (*PChainMultisig) GetFeeSigners() ([]ids.ID, error) { + return nil, nil +} + +func (*PChainMultisig) GetKind() PChainTxKind { + return Invalid +} + +func (*PChainMultisig) GetNetwork() (network.Network, error) { + return nil, nil +} + +func (*PChainMultisig) GetSubnetID() (ids.ID, error) { + return ids.Empty, nil +} + +func (*PChainMultisig) GetSubnetOwners() ([]ids.ID, int, error) { + return nil, 0, nil +} diff --git a/subnet/deploy_subnet.go b/subnet/deploy_subnet.go index cef7818..456c949 100644 --- a/subnet/deploy_subnet.go +++ b/subnet/deploy_subnet.go @@ -4,10 +4,12 @@ package subnet import ( - "avalanche-tooling-sdk-go/avalanche" - "avalanche-tooling-sdk-go/utils" "context" "fmt" + + "avalanche-tooling-sdk-go/avalanche" + + "avalanche-tooling-sdk-go/utils" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/keychain" "github.com/ava-labs/avalanchego/utils/formatting/address" @@ -43,11 +45,7 @@ func createSubnetTx(subnet *Subnet, wallet primary.Wallet) (*txs.Tx, error) { } // createBlockchainTx creates uncommitted createBlockchain transaction -func createBlockchainTx(subnet *Subnet, wallet primary.Wallet, network avalanche.Network, keyChain avalanche.Keychain) (*txs.Tx, error) { - wallet, err := loadCacheWallet(network, keyChain, wallet, subnet.SubnetID, subnet.TransferSubnetOwnershipTxID) - if err != nil { - return nil, err - } +func createBlockchainTx(subnet Subnet, wallet primary.Wallet, keyChain avalanche.Keychain) (*txs.Tx, error) { fxIDs := make([]ids.ID, 0) options := getMultisigTxOptions(keyChain.Keychain, subnet.SubnetAuthKeys) // create tx @@ -87,30 +85,3 @@ func getMultisigTxOptions(keychain keychain.Keychain, subnetAuthKeys []ids.Short options = append(options, common.WithChangeOwner(changeOwner)) return options } - -func loadCacheWallet(network avalanche.Network, keyChain avalanche.Keychain, wallet primary.Wallet, preloadTxs ...ids.ID) (primary.Wallet, error) { - var err error - if wallet == nil { - wallet, err = loadWallet(network, keyChain, preloadTxs...) - } - return wallet, err -} - -func loadWallet(network avalanche.Network, keyChain avalanche.Keychain, preloadTxs ...ids.ID) (primary.Wallet, error) { - ctx := context.Background() - // filter out ids.Empty txs - filteredTxs := utils.Filter(preloadTxs, func(e ids.ID) bool { return e != ids.Empty }) - wallet, err := primary.MakeWallet( - ctx, - &primary.WalletConfig{ - URI: network.Endpoint, - AVAXKeychain: keyChain.Keychain, - EthKeychain: secp256k1fx.NewKeychain(), - PChainTxsToFetch: set.Of(filteredTxs...), - }, - ) - if err != nil { - return nil, err - } - return wallet, nil -}