mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package x
|
|
|
|
import (
|
|
stdcontext "context"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/keychain"
|
|
"github.com/luxfi/node/vms/xvm/txs"
|
|
lux "github.com/luxfi/utxo"
|
|
)
|
|
|
|
var _ Signer = (*txSigner)(nil)
|
|
|
|
type Signer interface {
|
|
SignUnsigned(ctx stdcontext.Context, tx txs.UnsignedTx) (*txs.Tx, error)
|
|
Sign(ctx stdcontext.Context, tx *txs.Tx) error
|
|
}
|
|
|
|
type SignerBackend interface {
|
|
GetUTXO(ctx stdcontext.Context, chainID, utxoID ids.ID) (*lux.UTXO, error)
|
|
}
|
|
|
|
type txSigner struct {
|
|
kc keychain.Keychain
|
|
backend SignerBackend
|
|
}
|
|
|
|
func NewSigner(kc keychain.Keychain, backend SignerBackend) Signer {
|
|
return &txSigner{
|
|
kc: kc,
|
|
backend: backend,
|
|
}
|
|
}
|
|
|
|
func (s *txSigner) SignUnsigned(ctx stdcontext.Context, utx txs.UnsignedTx) (*txs.Tx, error) {
|
|
tx := &txs.Tx{Unsigned: utx}
|
|
return tx, s.Sign(ctx, tx)
|
|
}
|
|
|
|
func (s *txSigner) Sign(ctx stdcontext.Context, tx *txs.Tx) error {
|
|
return tx.Unsigned.Visit(&signerVisitor{
|
|
kc: s.kc,
|
|
backend: s.backend,
|
|
ctx: ctx,
|
|
tx: tx,
|
|
})
|
|
}
|