Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add err checks and other lint fixes #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ type RelayType uint64

const (
SingleHostAddr RelayType = 0
SingleHostName = 1
MultiHostName = 2
SingleHostName RelayType = 1
MultiHostName RelayType = 2
)

type singleHostAddr struct {
Expand Down
8 changes: 6 additions & 2 deletions cli/cmd/new_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ var newAddressCmd = &cobra.Command{
if err != nil {
return err
}
w.AddAddress()
client.SaveWallet(w)
if _, err := w.AddAddress(); err != nil {
return err
}
if err := client.SaveWallet(w); err != nil {
return err
}

return nil
},
Expand Down
4 changes: 2 additions & 2 deletions crypto/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestExtendedSigningKeyWithoutPassphrase(t *testing.T) {
got := NewXPrvKeyFromEntropy(entropy, "")
want, _ := hex.DecodeString(masterKeyWithoutPassphrase)

if bytes.Compare(got, want) != 0 {
if !bytes.Equal(got, want) {
t.Errorf("invalid master key\ngot: %x\nwant: %x\n", got, want)
}
}
Expand All @@ -32,7 +32,7 @@ func TestExtendedSigningKeyWithPassphrase(t *testing.T) {
got := NewXPrvKeyFromEntropy(entropy, passphrase)
want, _ := hex.DecodeString(masterKeyWithPassphrase)

if bytes.Compare(got, want) != 0 {
if !bytes.Equal(got, want) {
t.Errorf("invalid master key\ngot: %x\nwant: %x\n", got, want)
}
}
30 changes: 14 additions & 16 deletions internal/cbor/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ import (
// To unmarshal CBOR into an empty interface value, Unmarshal uses the
// following rules:
//
// CBOR booleans decode to bool.
// CBOR positive integers decode to uint64.
// CBOR negative integers decode to int64 (big.Int if value overflows).
// CBOR floating points decode to float64.
// CBOR byte strings decode to []byte.
// CBOR text strings decode to string.
// CBOR arrays decode to []interface{}.
// CBOR maps decode to map[interface{}]interface{}.
// CBOR null and undefined values decode to nil.
// CBOR times (tag 0 and 1) decode to time.Time.
// CBOR bignums (tag 2 and 3) decode to big.Int.
// CBOR booleans decode to bool.
// CBOR positive integers decode to uint64.
// CBOR negative integers decode to int64 (big.Int if value overflows).
// CBOR floating points decode to float64.
// CBOR byte strings decode to []byte.
// CBOR text strings decode to string.
// CBOR arrays decode to []interface{}.
// CBOR maps decode to map[interface{}]interface{}.
// CBOR null and undefined values decode to nil.
// CBOR times (tag 0 and 1) decode to time.Time.
// CBOR bignums (tag 2 and 3) decode to big.Int.
//
// To unmarshal a CBOR array into a slice, Unmarshal allocates a new slice
// if the CBOR array is empty or slice capacity is less than CBOR array length.
Expand All @@ -75,9 +75,9 @@ import (
// To unmarshal a CBOR map into a struct, Unmarshal matches CBOR map keys to the
// keys in the following priority:
//
// 1. "cbor" key in struct field tag,
// 2. "json" key in struct field tag,
// 3. struct field name.
// 1. "cbor" key in struct field tag,
// 2. "json" key in struct field tag,
// 3. struct field name.
//
// Unmarshal tries an exact match for field name, then a case-insensitive match.
// Map key-value pairs without corresponding struct fields are ignored. See
Expand Down Expand Up @@ -728,8 +728,6 @@ func (d *decoder) parseToValue(v reflect.Value, tInfo *typeInfo) error { //nolin
}
v.Set(reflect.ValueOf(NewByteString(rb.Bytes())))
return nil
} else {
return fillByteString(t, b, v)
}
return fillByteString(t, b, v)
case cborTypeTextString:
Expand Down
8 changes: 4 additions & 4 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ type ProtocolParams struct {
ProtocolVersion ProtocolVersion
MinPoolCost Coin
CoinsPerUTXOWord Coin
CostModels interface{}
ExecutionCosts interface{}
MaxTxExUnits interface{}
MaxBlockTxExUnits interface{}
CostModels any
ExecutionCosts any
MaxTxExUnits any
MaxBlockTxExUnits any
MaxValueSize uint
CollateralPercentage uint
MaxCollateralInputs uint
Expand Down
3 changes: 1 addition & 2 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func (ns *NativeScript) Hash() (Hash28, error) {
if err != nil {
return nil, err
}
bytes = append([]byte{byte(NativeScriptNamespace)}, bytes...)
return Blake224Hash(append(bytes))
return Blake224Hash(append([]byte{byte(NativeScriptNamespace)}, bytes...))
}

// Bytes returns the CBOR encoding of the script as bytes.
Expand Down
4 changes: 3 additions & 1 deletion wallet/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (bdb *badgerDB) Get() ([]*Wallet, error) {
return err
}
wallet := &Wallet{}
wallet.unmarshal(value)
if err := wallet.unmarshal(value); err != nil {
return err
}
wallets = append(wallets, wallet)
}
return nil
Expand Down
5 changes: 4 additions & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ func (w *Wallet) Transfer(receiver cardano.Address, amount *cardano.Value) (*car
}

if cmp := balance.Cmp(amount); cmp == -1 || cmp == 2 {
return nil, fmt.Errorf("Not enough balance, %v > %v", amount, balance)
return nil, fmt.Errorf("not enough balance, %v > %v", amount, balance)
}

// Find utxos that cover the amount to transfer
pickedUtxos := []cardano.UTxO{}
utxos, err := w.findUtxos()
if err != nil {
return nil, fmt.Errorf("cannot find utxos: %v", err)
}
pickedUtxosAmount := cardano.NewValue(0)
for _, utxo := range utxos {
if pickedUtxosAmount.Cmp(amount) == 1 {
Expand Down