@@ -159,6 +159,19 @@ type ProposalTxBuilder interface {
159
159
changeAddr ids.ShortID ,
160
160
) (* txs.Tx , error )
161
161
162
+ // Creates a transaction that transfers ownership of [subnetID]
163
+ // threshold: [threshold] of [ownerAddrs] needed to manage this subnet
164
+ // ownerAddrs: control addresses for the new subnet
165
+ // keys: keys to use for modifying the subnet
166
+ // changeAddr: address to send change to, if there is any
167
+ NewTransferSubnetOwnershipTx (
168
+ subnetID ids.ID ,
169
+ threshold uint32 ,
170
+ ownerAddrs []ids.ShortID ,
171
+ keys []* secp256k1.PrivateKey ,
172
+ changeAddr ids.ShortID ,
173
+ ) (* txs.Tx , error )
174
+
162
175
// newAdvanceTimeTx creates a new tx that, if it is accepted and followed by a
163
176
// Commit block, will set the chain's timestamp to [timestamp].
164
177
NewAdvanceTimeTx (timestamp time.Time ) (* txs.Tx , error )
@@ -609,3 +622,42 @@ func (b *builder) NewRewardValidatorTx(txID ids.ID) (*txs.Tx, error) {
609
622
610
623
return tx , tx .SyntacticVerify (b .ctx )
611
624
}
625
+
626
+ func (b * builder ) NewTransferSubnetOwnershipTx (
627
+ subnetID ids.ID ,
628
+ threshold uint32 ,
629
+ ownerAddrs []ids.ShortID ,
630
+ keys []* secp256k1.PrivateKey ,
631
+ changeAddr ids.ShortID ,
632
+ ) (* txs.Tx , error ) {
633
+ ins , outs , _ , signers , err := b .Spend (b .state , keys , 0 , b .cfg .TxFee , changeAddr )
634
+ if err != nil {
635
+ return nil , fmt .Errorf ("couldn't generate tx inputs/outputs: %w" , err )
636
+ }
637
+
638
+ subnetAuth , subnetSigners , err := b .Authorize (b .state , subnetID , keys )
639
+ if err != nil {
640
+ return nil , fmt .Errorf ("couldn't authorize tx's subnet restrictions: %w" , err )
641
+ }
642
+ signers = append (signers , subnetSigners )
643
+
644
+ utx := & txs.TransferSubnetOwnershipTx {
645
+ BaseTx : txs.BaseTx {BaseTx : avax.BaseTx {
646
+ NetworkID : b .ctx .NetworkID ,
647
+ BlockchainID : b .ctx .ChainID ,
648
+ Ins : ins ,
649
+ Outs : outs ,
650
+ }},
651
+ Subnet : subnetID ,
652
+ SubnetAuth : subnetAuth ,
653
+ Owner : & secp256k1fx.OutputOwners {
654
+ Threshold : threshold ,
655
+ Addrs : ownerAddrs ,
656
+ },
657
+ }
658
+ tx , err := txs .NewSigned (utx , txs .Codec , signers )
659
+ if err != nil {
660
+ return nil , err
661
+ }
662
+ return tx , tx .SyntacticVerify (b .ctx )
663
+ }
0 commit comments