Skip to content

Commit

Permalink
renamed names
Browse files Browse the repository at this point in the history
  • Loading branch information
augustync committed Oct 23, 2024
1 parent 2d6ae23 commit 1294544
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 45 deletions.
4 changes: 2 additions & 2 deletions config/config_to_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/bitcoin-sv/spv-wallet/conv"
"github.com/bitcoin-sv/spv-wallet/engine"
"github.com/bitcoin-sv/spv-wallet/engine/chain/models"
chainmodels "github.com/bitcoin-sv/spv-wallet/engine/chain/models"
"github.com/bitcoin-sv/spv-wallet/engine/cluster"
"github.com/bitcoin-sv/spv-wallet/engine/datastore"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *AppConfig) addHttpClientOpts(options []engine.ClientOps) []engine.Clien

func (c *AppConfig) addCustomFeeUnit(options []engine.ClientOps) []engine.ClientOps {
if c.CustomFeeUnit != nil {
satoshis, err := conv.ConvertIntToUint64(c.CustomFeeUnit.Satoshis)
satoshis, err := conv.IntToUint64(c.CustomFeeUnit.Satoshis)
if err != nil {
panic(spverrors.Wrapf(err, "error converting custom fee unit satoshis"))
}
Expand Down
40 changes: 16 additions & 24 deletions conv/convert_primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,61 @@ import (
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
)

// ConvertInt64ToUint32 will convert an int64 to a uint32, with range checks
func ConvertInt64ToUint32(value int64) (uint32, error) {
// Int64ToUint32 will convert an int64 to a uint32, with range checks
func Int64ToUint32(value int64) (uint32, error) {
if value < 0 || value > math.MaxUint32 {
return 0, spverrors.ErrInvalidUint32
}
return uint32(value), nil
}

// ConvertUint32ToInt64 will convert a uint32 to an int64 (safe as uint32 fits into int64)
func ConvertUint32ToInt64(value uint32) int64 {
// Uint32ToInt64 will convert a uint32 to an int64 (safe as uint32 fits into int64)
func Uint32ToInt64(value uint32) int64 {
return int64(value)
}

// ConvertUint64ToInt64 will convert a uint64 to an int64, with range checks
func ConvertUint64ToInt64(value uint64) (int64, error) {
// Uint64ToInt64 will convert a uint64 to an int64, with range checks
func Uint64ToInt64(value uint64) (int64, error) {
if value > math.MaxInt64 {
return 0, spverrors.ErrInvalidInt64
}
return int64(value), nil
}

// ConvertInt64ToUint64 will convert an int64 to a uint64, with range checks
func ConvertInt64ToUint64(value int64) (uint64, error) {
// Int64ToUint64 will convert an int64 to a uint64, with range checks
func Int64ToUint64(value int64) (uint64, error) {
if value < 0 {
return 0, spverrors.ErrInvalidUint64
}
return uint64(value), nil
}

// ConvertUint64ToInt will convert a uint64 to an int, with range checks
func ConvertUint64ToInt(value uint64) (int, error) {
// Uint64ToInt will convert a uint64 to an int, with range checks
func Uint64ToInt(value uint64) (int, error) {
if value > math.MaxInt {
return 0, spverrors.ErrInvalidInt
}
return int(value), nil
}

// ConvertIntToUint64 will convert an int to a uint64, with range checks
func ConvertIntToUint64(value int) (uint64, error) {
// IntToUint64 will convert an int to a uint64, with range checks
func IntToUint64(value int) (uint64, error) {
if value < 0 {
return 0, spverrors.ErrInvalidUint64
}
return uint64(value), nil
}

// ConvertIntToUint32 will convert an int to a uint32, with range checks
func ConvertIntToUint32(value int) (uint32, error) {
// IntToUint32 will convert an int to a uint32, with range checks
func IntToUint32(value int) (uint32, error) {
if value < 0 || value > math.MaxUint32 {
return 0, spverrors.ErrInvalidUint32
}
return uint32(value), nil
}

// SafeVarIntToInt will convert a VarInt to an int, with range checks
func SafeVarIntToInt(varInt *sdk.VarInt) (int, error) {
// VarIntToInt will convert a VarInt to an int, with range checks
func VarIntToInt(varInt *sdk.VarInt) (int, error) {
if varInt == nil {
return 0, spverrors.ErrInvalidInt
}
Expand All @@ -73,11 +73,3 @@ func SafeVarIntToInt(varInt *sdk.VarInt) (int, error) {
// Convert the VarInt to an int
return int(i), nil
}

// ConvertToIntUint64 will convert an int to a uint64, with range checks
func ConvertToIntUint64(value int) (uint64, error) {
if value < 0 {
return 0, spverrors.ErrInvalidUint64
}
return uint64(value), nil
}
4 changes: 2 additions & 2 deletions engine/action_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

trx "github.com/bitcoin-sv/go-sdk/transaction"
"github.com/bitcoin-sv/spv-wallet/conv"
"github.com/bitcoin-sv/spv-wallet/engine/chain/models"
chainmodels "github.com/bitcoin-sv/spv-wallet/engine/chain/models"
"github.com/bitcoin-sv/spv-wallet/engine/datastore"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/engine/utils"
Expand Down Expand Up @@ -377,7 +377,7 @@ func (c *Client) HandleTxCallback(ctx context.Context, callbackResp *chainmodels
}

tx.BlockHash = callbackResp.BlockHash
blockHeight, err := conv.ConvertInt64ToUint64(callbackResp.BlockHeight)
blockHeight, err := conv.Int64ToUint64(callbackResp.BlockHeight)
if err != nil {
return spverrors.Wrapf(err, "failed to convert block height to uint64 - tx: %v", callbackResp.BlockHeight)
}
Expand Down
2 changes: 1 addition & 1 deletion engine/beef_tx_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func toBeefBytes(tx *trx.Transaction, bumps BUMPs) []byte {
bumpIdx := getBumpPathIndex(tx, bumps)
if bumpIdx > -1 {
txBeefBytes = append(txBeefBytes, hasBUMP)
idx, err := conv.ConvertIntToUint64(bumpIdx)
idx, err := conv.IntToUint64(bumpIdx)
if err != nil {
panic(spverrors.Wrapf(err, "error converting bump index"))
}
Expand Down
6 changes: 3 additions & 3 deletions engine/model_draft_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (m *DraftTransaction) estimateSize() uint64 {

inputSize := trx.VarInt(len(m.Configuration.Inputs))

value, err := conv.ConvertIntToUint64(inputSize.Length())
value, err := conv.IntToUint64(inputSize.Length())
if err != nil {
m.client.Logger().Error().Msg(err.Error())
return 0
Expand All @@ -513,7 +513,7 @@ func (m *DraftTransaction) estimateSize() uint64 {
}

outputSize := trx.VarInt(len(m.Configuration.Outputs))
value, err = conv.ConvertIntToUint64(outputSize.Length())
value, err = conv.IntToUint64(outputSize.Length())
if err != nil {
m.client.Logger().Error().Msg(err.Error())
return 0
Expand Down Expand Up @@ -898,7 +898,7 @@ func (m *DraftTransaction) SignInputs(xPriv *compat.ExtendedKey) (signedHex stri
return
}

idx32, conversionError := conv.ConvertIntToUint32(index)
idx32, conversionError := conv.IntToUint32(index)
if err != nil {
return "", spverrors.Wrapf(conversionError, "failed to convert index %d to uint32", index)
}
Expand Down
2 changes: 1 addition & 1 deletion engine/model_paymail_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (m *PaymailAddress) incrementExternalXpubDerivationSeq(ctx context.Context)
return err
}

newNumU32, err := conv.ConvertInt64ToUint32(newNum)
newNumU32, err := conv.Int64ToUint32(newNum)
if err != nil {
return spverrors.Wrapf(err, "failed to convert int64 to uint32")
}
Expand Down
6 changes: 3 additions & 3 deletions engine/model_xpubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (m *Xpub) incrementBalance(ctx context.Context, balanceIncrement int64) err
return err
}

newBalanceU64, err := conv.ConvertInt64ToUint64(newBalance)
newBalanceU64, err := conv.Int64ToUint64(newBalance)
if err != nil {
return spverrors.Wrapf(err, "failed to convert int64 to uint64")
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (m *Xpub) incrementNextNum(ctx context.Context, chain uint32) (uint32, erro
return 0, err
}

newNumU32, errConversion := conv.ConvertInt64ToUint32(newNum)
newNumU32, errConversion := conv.Int64ToUint32(newNum)
if err != nil {
return 0, spverrors.Wrapf(errConversion, "failed to convert int64 to uint32")
}
Expand All @@ -278,7 +278,7 @@ func (m *Xpub) incrementNextNum(ctx context.Context, chain uint32) (uint32, erro
// Calculate newNumMinusOne
newNumMinusOne := newNum - 1

newNumMinusOneU32, errConversion := conv.ConvertInt64ToUint32(newNumMinusOne)
newNumMinusOneU32, errConversion := conv.Int64ToUint32(newNumMinusOne)
if err != nil {
return 0, spverrors.Wrapf(errConversion, "failed to convert int64 to uint32")
}
Expand Down
2 changes: 1 addition & 1 deletion engine/paymail_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func saveBEEFTxInputs(ctx context.Context, c ClientInterface, dBeef *beef.Decode
for _, input := range inputsToAdd {
var bump *BUMP
if input.BumpIndex != nil { // mined
bumpIndex, err := conv.SafeVarIntToInt(input.BumpIndex)
bumpIndex, err := conv.VarIntToInt(input.BumpIndex)
if err != nil {
c.Logger().Error().Msgf("error in saveBEEFTxInputs: %v for beef: %v", err, dBeef)
}
Expand Down
2 changes: 1 addition & 1 deletion engine/pike_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *PikePaymentServiceProvider) saveDestinations(
dst := newDestination(pAddress.XpubID, script, append(p.client.DefaultModelOptions(), opts...)...)
dst.DerivationMethod = PIKEDerivationMethod
dst.SenderXpub = senderPubKeyHex
idx32, err := conv.ConvertIntToUint32(index)
idx32, err := conv.IntToUint32(index)
if err != nil {
return spverrors.Wrapf(err, "failed to convert int to uint32")
}
Expand Down
10 changes: 5 additions & 5 deletions engine/tx_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (m *Transaction) processUtxos(ctx context.Context) error {
}

m.TotalValue, m.Fee = m.getValues()
inputLen, err := conv.ConvertIntToUint32(len(m.parsedTx.Inputs))
inputLen, err := conv.IntToUint32(len(m.parsedTx.Inputs))
if err != nil {
return spverrors.Wrapf(err, "failed to convert int to uint32")
}
m.NumberOfInputs = inputLen

outputLen, err := conv.ConvertIntToUint32(len(m.parsedTx.Outputs))
outputLen, err := conv.IntToUint32(len(m.parsedTx.Outputs))
if err != nil {
return spverrors.Wrapf(err, "failed to convert int to uint32")
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (m *Transaction) _processInputs(ctx context.Context) (err error) {
if utxo.Satoshis > math.MaxInt64 {
return fmt.Errorf("utxo.Satoshis exceeds the maximum value for int64: %d", utxo.Satoshis)
}
satoshis, err := conv.ConvertUint64ToInt64(utxo.Satoshis)
satoshis, err := conv.Uint64ToInt64(utxo.Satoshis)
if err != nil {
return spverrors.Wrapf(err, "failed to convert uint64 to int64")
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (m *Transaction) _processOutputs(ctx context.Context) (err error) {
); err != nil {
return
} else if destination != nil {
i32, err := conv.ConvertIntToUint32(i)
i32, err := conv.IntToUint32(i)
if err != nil {
return spverrors.Wrapf(err, "failed to convert int to uint32")
}
Expand All @@ -179,7 +179,7 @@ func (m *Transaction) _processOutputs(ctx context.Context) (err error) {
if _, ok := m.XpubOutputValue[destination.XpubID]; !ok {
m.XpubOutputValue[destination.XpubID] = 0
}
amountInt64, err := conv.ConvertUint64ToInt64(amount)
amountInt64, err := conv.Uint64ToInt64(amount)
if err != nil {
return spverrors.Wrapf(err, "failed to convert uint64 to int64")
}
Expand Down
2 changes: 1 addition & 1 deletion engine/tx_sync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func processSyncTransactions(ctx context.Context, client *Client) {
} else {
tx.SetBUMP(bump)
}
blockHeight, err := conv.ConvertInt64ToUint64(txInfo.BlockHeight)
blockHeight, err := conv.Int64ToUint64(txInfo.BlockHeight)
if err != nil {
panic(spverrors.Wrapf(err, "cannot convert block height"))
}
Expand Down
2 changes: 1 addition & 1 deletion engine/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func GetChildNumsFromHex(hexHash string) ([]uint32, error) {
}

result := num % MaxInt32
resultU32, err := conv.ConvertInt64ToUint32(result)
resultU32, err := conv.Int64ToUint32(result)
if err != nil {
return nil, spverrors.Wrapf(err, "cannot convert int64 to uint32")
}
Expand Down

0 comments on commit 1294544

Please sign in to comment.