-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ava-labs/apply-multisig
use multisig as create tx output, and wrap wallet for multisig options
- Loading branch information
Showing
4 changed files
with
102 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package subnet | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/crypto/keychain" | ||
"github.com/ava-labs/avalanchego/utils/set" | ||
"github.com/ava-labs/avalanchego/vms/secp256k1fx" | ||
"github.com/ava-labs/avalanchego/wallet/subnet/primary" | ||
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common" | ||
) | ||
|
||
type Wallet struct { | ||
primary.Wallet | ||
keychain keychain.Keychain | ||
options []common.Option | ||
} | ||
|
||
func NewWallet(ctx context.Context, config *primary.WalletConfig) (Wallet, error) { | ||
wallet, err := primary.MakeWallet( | ||
ctx, | ||
config, | ||
) | ||
return Wallet{ | ||
Wallet: wallet, | ||
keychain: config.AVAXKeychain, | ||
}, err | ||
} | ||
|
||
// secure that a fee paying address (wallet's keychain) will receive the change, | ||
// and not a randomly selected auth key that may not be paying fees | ||
func (w *Wallet) SecureWalletIsChangeOwner() { | ||
addrs := w.keychain.Addresses().List() | ||
changeAddr := addrs[0] | ||
// set change to go to wallet addr (instead of any other subnet auth key) | ||
changeOwner := &secp256k1fx.OutputOwners{ | ||
Threshold: 1, | ||
Addrs: []ids.ShortID{changeAddr}, | ||
} | ||
// TODO: avoid continuosly adding the options in succesive calls | ||
w.options = append(w.options, common.WithChangeOwner(changeOwner)) | ||
w.Wallet = primary.NewWalletWithOptions(w.Wallet, w.options...) | ||
} | ||
|
||
// set auth keys that will also used when signing txs, besides the wallet's keychain fee paying ones | ||
func (w *Wallet) SetAuthKeys(authKeys []ids.ShortID) { | ||
addrs := w.keychain.Addresses().List() | ||
addrsSet := set.Set[ids.ShortID]{} | ||
addrsSet.Add(addrs...) | ||
addrsSet.Add(authKeys...) | ||
// TODO: avoid continuosly adding the options in succesive calls | ||
w.options = append(w.options, common.WithCustomAddresses(addrsSet)) | ||
w.Wallet = primary.NewWalletWithOptions(w.Wallet, w.options...) | ||
} | ||
|
||
func (w *Wallet) SetSubnetAuthMultisig(authKeys []ids.ShortID) { | ||
w.SecureWalletIsChangeOwner() | ||
w.SetAuthKeys(authKeys) | ||
} |