Skip to content

Commit

Permalink
transaction object
Browse files Browse the repository at this point in the history
  • Loading branch information
sukantoraymond committed May 22, 2024
1 parent fb614e7 commit 0d206b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
8 changes: 4 additions & 4 deletions subnet/deploy_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ 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) {

Check warning on line 46 in subnet/deploy_subnet.go

View workflow job for this annotation

GitHub Actions / Lint

unused-parameter: parameter 'network' seems to be unused, consider removing or renaming it as _ (revive)
wallet, err := loadCacheWallet(network, keyChain, wallet, subnet.SubnetID, subnet.TransferSubnetOwnershipTxID)
if err != nil {
return nil, err
}
//wallet, err := loadCacheWallet(network, keyChain, wallet, subnet.SubnetID, subnet.TransferSubnetOwnershipTxID)

Check failure on line 47 in subnet/deploy_subnet.go

View workflow job for this annotation

GitHub Actions / Lint

commentFormatting: put a space between `//` and comment text (gocritic)
//if err != nil {
// return nil, err
//}
fxIDs := make([]ids.ID, 0)
options := getMultisigTxOptions(keyChain.Keychain, subnet.SubnetAuthKeys)
// create tx
Expand Down
52 changes: 52 additions & 0 deletions transaction/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.

Check failure on line 1 in transaction/transaction.go

View workflow job for this annotation

GitHub Actions / Lint

: # avalanche-tooling-sdk-go/transaction
// See the file LICENSE for licensing terms.

package transaction

import (
"fmt"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
"time"
)

func Commit(
wallet primary.Wallet,
tx *txs.Tx,
waitForTxAcceptance bool,
) (ids.ID, error) {
const (
repeats = 3
sleepBetweenRepeats = 2 * time.Second
)
var issueTxErr error
//wallet, err := d.loadCacheWallet()
//if err != nil {
// return ids.Empty, err
//}
for i := 0; i < repeats; i++ {
ctx, cancel := utils.GetAPILargeContext()

Check failure on line 30 in transaction/transaction.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: utils
defer cancel()
options := []common.Option{common.WithContext(ctx)}
if !waitForTxAcceptance {
options = append(options, common.WithAssumeDecided())
}
issueTxErr = wallet.P().IssueTx(tx, options...)
if issueTxErr == nil {
break
}
if ctx.Err() != nil {
issueTxErr = fmt.Errorf("timeout issuing/verifying tx with ID %s: %w", tx.ID(), issueTxErr)
} else {
issueTxErr = fmt.Errorf("error issuing tx with ID %s: %w", tx.ID(), issueTxErr)
}
ux.Logger.RedXToUser("%s", issueTxErr)

Check failure on line 45 in transaction/transaction.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: ux
time.Sleep(sleepBetweenRepeats)
}
if issueTxErr != nil {
d.cleanCacheWallet()

Check failure on line 49 in transaction/transaction.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: d (typecheck)
}
return tx.ID(), issueTxErr
}

0 comments on commit 0d206b3

Please sign in to comment.