-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repackaged wallet backend for P-chain
- Loading branch information
Showing
15 changed files
with
248 additions
and
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package backends | ||
|
||
import ( | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/vms/components/avax" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/fx" | ||
|
||
stdcontext "context" | ||
) | ||
|
||
var ( | ||
_ BuilderBackend = Backend(nil) | ||
_ SignerBackend = Backend(nil) | ||
) | ||
|
||
type Backend interface { | ||
Context | ||
UTXOs(ctx stdcontext.Context, sourceChainID ids.ID) ([]*avax.UTXO, error) | ||
GetSubnetOwner(ctx stdcontext.Context, subnetID ids.ID) (fx.Owner, error) | ||
GetUTXO(ctx stdcontext.Context, chainID, utxoID ids.ID) (*avax.UTXO, error) | ||
} | ||
|
||
type SignerBackend interface { | ||
GetUTXO(ctx stdcontext.Context, chainID, utxoID ids.ID) (*avax.UTXO, error) | ||
GetSubnetOwner(ctx stdcontext.Context, subnetID ids.ID) (fx.Owner, error) | ||
} | ||
|
||
type BuilderBackend interface { | ||
Context | ||
UTXOs(ctx stdcontext.Context, sourceChainID ids.ID) ([]*avax.UTXO, error) | ||
GetSubnetOwner(ctx stdcontext.Context, subnetID ids.ID) (fx.Owner, error) | ||
} |
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,119 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package backends | ||
|
||
import ( | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/snow" | ||
"github.com/ava-labs/avalanchego/utils/constants" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
) | ||
|
||
const Alias = "P" | ||
|
||
var _ Context = (*builderCtx)(nil) | ||
|
||
type Context interface { | ||
NetworkID() uint32 | ||
AVAXAssetID() ids.ID | ||
BaseTxFee() uint64 | ||
CreateSubnetTxFee() uint64 | ||
TransformSubnetTxFee() uint64 | ||
CreateBlockchainTxFee() uint64 | ||
AddPrimaryNetworkValidatorFee() uint64 | ||
AddPrimaryNetworkDelegatorFee() uint64 | ||
AddSubnetValidatorFee() uint64 | ||
AddSubnetDelegatorFee() uint64 | ||
} | ||
|
||
type builderCtx struct { | ||
networkID uint32 | ||
avaxAssetID ids.ID | ||
baseTxFee uint64 | ||
createSubnetTxFee uint64 | ||
transformSubnetTxFee uint64 | ||
createBlockchainTxFee uint64 | ||
addPrimaryNetworkValidatorFee uint64 | ||
addPrimaryNetworkDelegatorFee uint64 | ||
addSubnetValidatorFee uint64 | ||
addSubnetDelegatorFee uint64 | ||
} | ||
|
||
func NewContext( | ||
networkID uint32, | ||
avaxAssetID ids.ID, | ||
baseTxFee uint64, | ||
createSubnetTxFee uint64, | ||
transformSubnetTxFee uint64, | ||
createBlockchainTxFee uint64, | ||
addPrimaryNetworkValidatorFee uint64, | ||
addPrimaryNetworkDelegatorFee uint64, | ||
addSubnetValidatorFee uint64, | ||
addSubnetDelegatorFee uint64, | ||
) Context { | ||
return &builderCtx{ | ||
networkID: networkID, | ||
avaxAssetID: avaxAssetID, | ||
baseTxFee: baseTxFee, | ||
createSubnetTxFee: createSubnetTxFee, | ||
transformSubnetTxFee: transformSubnetTxFee, | ||
createBlockchainTxFee: createBlockchainTxFee, | ||
addPrimaryNetworkValidatorFee: addPrimaryNetworkValidatorFee, | ||
addPrimaryNetworkDelegatorFee: addPrimaryNetworkDelegatorFee, | ||
addSubnetValidatorFee: addSubnetValidatorFee, | ||
addSubnetDelegatorFee: addSubnetDelegatorFee, | ||
} | ||
} | ||
|
||
func (c *builderCtx) NetworkID() uint32 { | ||
return c.networkID | ||
} | ||
|
||
func (c *builderCtx) AVAXAssetID() ids.ID { | ||
return c.avaxAssetID | ||
} | ||
|
||
func (c *builderCtx) BaseTxFee() uint64 { | ||
return c.baseTxFee | ||
} | ||
|
||
func (c *builderCtx) CreateSubnetTxFee() uint64 { | ||
return c.createSubnetTxFee | ||
} | ||
|
||
func (c *builderCtx) TransformSubnetTxFee() uint64 { | ||
return c.transformSubnetTxFee | ||
} | ||
|
||
func (c *builderCtx) CreateBlockchainTxFee() uint64 { | ||
return c.createBlockchainTxFee | ||
} | ||
|
||
func (c *builderCtx) AddPrimaryNetworkValidatorFee() uint64 { | ||
return c.addPrimaryNetworkValidatorFee | ||
} | ||
|
||
func (c *builderCtx) AddPrimaryNetworkDelegatorFee() uint64 { | ||
return c.addPrimaryNetworkDelegatorFee | ||
} | ||
|
||
func (c *builderCtx) AddSubnetValidatorFee() uint64 { | ||
return c.addSubnetValidatorFee | ||
} | ||
|
||
func (c *builderCtx) AddSubnetDelegatorFee() uint64 { | ||
return c.addSubnetDelegatorFee | ||
} | ||
|
||
func NewSnowContext(networkID uint32, avaxAssetID ids.ID) (*snow.Context, error) { | ||
lookup := ids.NewAliaser() | ||
return &snow.Context{ | ||
NetworkID: networkID, | ||
SubnetID: constants.PrimaryNetworkID, | ||
ChainID: constants.PlatformChainID, | ||
AVAXAssetID: avaxAssetID, | ||
Log: logging.NoLog{}, | ||
BCLookup: lookup, | ||
}, lookup.Alias(constants.PlatformChainID, Alias) | ||
} |
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
Oops, something went wrong.