chore: fmt.Errorf(static) → errors.New
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d8eb6c5478
commit
aefec104d4
13 changed files with 36 additions and 26 deletions
|
|
@ -8,10 +8,11 @@
|
|||
package chain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
store "forge.lthn.ai/core/go-store"
|
||||
"forge.lthn.ai/core/go-blockchain/types"
|
||||
store "forge.lthn.ai/core/go-store"
|
||||
)
|
||||
|
||||
// Chain manages blockchain storage and indexing.
|
||||
|
|
@ -41,7 +42,7 @@ func (c *Chain) TopBlock() (*types.Block, *BlockMeta, error) {
|
|||
return nil, nil, err
|
||||
}
|
||||
if h == 0 {
|
||||
return nil, nil, fmt.Errorf("chain: no blocks stored")
|
||||
return nil, nil, errors.New("chain: no blocks stored")
|
||||
}
|
||||
return c.GetBlockByHeight(h - 1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
|
|
@ -413,7 +414,7 @@ var aggregatedRE = regexp.MustCompile(`"AGGREGATED"\s*:\s*\{([^}]+)\}`)
|
|||
func parseBlockHeader(objectInJSON string) (*types.BlockHeader, error) {
|
||||
m := aggregatedRE.FindStringSubmatch(objectInJSON)
|
||||
if m == nil {
|
||||
return nil, fmt.Errorf("AGGREGATED section not found in object_in_json")
|
||||
return nil, errors.New("AGGREGATED section not found in object_in_json")
|
||||
}
|
||||
|
||||
var hj blockHeaderJSON
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package chain
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"forge.lthn.ai/core/go-blockchain/config"
|
||||
|
|
@ -31,7 +32,7 @@ func (c *Chain) ValidateHeader(b *types.Block, expectedHeight uint64) error {
|
|||
// Genesis block: prev_id must be zero.
|
||||
if expectedHeight == 0 {
|
||||
if !b.PrevID.IsZero() {
|
||||
return fmt.Errorf("validate: genesis block has non-zero prev_id")
|
||||
return errors.New("validate: genesis block has non-zero prev_id")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
package consensus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/bits"
|
||||
|
||||
|
|
@ -55,7 +56,7 @@ func BlockReward(baseReward, blockSize, medianSize uint64) (uint64, error) {
|
|||
|
||||
// Since hi1 should be 0 for reasonable block sizes, simplify:
|
||||
if hi1 > 0 {
|
||||
return 0, fmt.Errorf("consensus: reward overflow")
|
||||
return 0, errors.New("consensus: reward overflow")
|
||||
}
|
||||
hi2, lo2 := bits.Mul64(baseReward, lo1)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
package consensus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"forge.lthn.ai/core/go-blockchain/config"
|
||||
|
|
@ -222,7 +223,7 @@ func verifyV2Signatures(tx *types.Transaction, getZCRingOutputs ZCRingOutputsFn)
|
|||
// Verify BPP range proof if present.
|
||||
if len(proofs.bppProofBytes) > 0 && len(proofs.bppCommitments) > 0 {
|
||||
if !crypto.VerifyBPP(proofs.bppProofBytes, proofs.bppCommitments) {
|
||||
return fmt.Errorf("consensus: BPP range proof verification failed")
|
||||
return errors.New("consensus: BPP range proof verification failed")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ func PointMul8(pk [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&result[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return result, fmt.Errorf("crypto: point_mul8 failed")
|
||||
return result, errors.New("crypto: point_mul8 failed")
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ func PointDiv8(pk [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&result[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return result, fmt.Errorf("crypto: point_div8 failed")
|
||||
return result, errors.New("crypto: point_div8 failed")
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ func PointSub(a, b [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&result[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return result, fmt.Errorf("crypto: point_sub failed")
|
||||
return result, errors.New("crypto: point_sub failed")
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ func GenerateCLSAGGG(hash [32]byte, ring []byte, ringSize int,
|
|||
(*C.uint8_t)(unsafe.Pointer(&sig[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return nil, fmt.Errorf("crypto: generate_CLSAG_GG failed")
|
||||
return nil, errors.New("crypto: generate_CLSAG_GG failed")
|
||||
}
|
||||
return sig, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
|
@ -51,7 +52,7 @@ func GenerateKeyDerivation(pub [32]byte, sec [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&d[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return d, fmt.Errorf("crypto: generate_key_derivation failed")
|
||||
return d, errors.New("crypto: generate_key_derivation failed")
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
|
@ -66,7 +67,7 @@ func DerivePublicKey(derivation [32]byte, index uint64, base [32]byte) ([32]byte
|
|||
(*C.uint8_t)(unsafe.Pointer(&derived[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return derived, fmt.Errorf("crypto: derive_public_key failed")
|
||||
return derived, errors.New("crypto: derive_public_key failed")
|
||||
}
|
||||
return derived, nil
|
||||
}
|
||||
|
|
@ -81,7 +82,7 @@ func DeriveSecretKey(derivation [32]byte, index uint64, base [32]byte) ([32]byte
|
|||
(*C.uint8_t)(unsafe.Pointer(&derived[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return derived, fmt.Errorf("crypto: derive_secret_key failed")
|
||||
return derived, errors.New("crypto: derive_secret_key failed")
|
||||
}
|
||||
return derived, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ func GenerateKeyImage(pub [32]byte, sec [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&ki[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return ki, fmt.Errorf("crypto: generate_key_image failed")
|
||||
return ki, errors.New("crypto: generate_key_image failed")
|
||||
}
|
||||
return ki, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ func GenerateSignature(hash [32]byte, pub [32]byte, sec [32]byte) ([64]byte, err
|
|||
(*C.uint8_t)(unsafe.Pointer(&sig[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return sig, fmt.Errorf("crypto: generate_signature failed")
|
||||
return sig, errors.New("crypto: generate_signature failed")
|
||||
}
|
||||
return sig, nil
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ func GenerateRingSignature(hash [32]byte, image [32]byte, pubs [][32]byte,
|
|||
(*C.uint8_t)(unsafe.Pointer(&flatSigs[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return nil, fmt.Errorf("crypto: generate_ring_signature failed")
|
||||
return nil, errors.New("crypto: generate_ring_signature failed")
|
||||
}
|
||||
|
||||
sigs := make([][64]byte, n)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
|
|
@ -54,8 +55,8 @@ type Account struct {
|
|||
SpendSecretKey types.SecretKey `json:"spend_secret_key"`
|
||||
ViewPublicKey types.PublicKey `json:"view_public_key"`
|
||||
ViewSecretKey types.SecretKey `json:"view_secret_key"`
|
||||
CreatedAt uint64 `json:"created_at"`
|
||||
Flags uint8 `json:"flags"`
|
||||
CreatedAt uint64 `json:"created_at"`
|
||||
Flags uint8 `json:"flags"`
|
||||
}
|
||||
|
||||
// GenerateAccount creates a new account with random spend keys and a
|
||||
|
|
@ -162,7 +163,7 @@ func LoadAccount(s *store.Store, password string) (*Account, error) {
|
|||
}
|
||||
|
||||
if len(blob) < saltLen+nonceLen+1 {
|
||||
return nil, fmt.Errorf("wallet: account data too short")
|
||||
return nil, errors.New("wallet: account data too short")
|
||||
}
|
||||
|
||||
salt := blob[:saltLen]
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ package wallet
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
|
|
@ -170,7 +171,7 @@ func (b *V1Builder) buildInput(src *Transfer) (types.TxInputToKey, inputMeta, er
|
|||
}
|
||||
}
|
||||
if realIdx < 0 {
|
||||
return types.TxInputToKey{}, inputMeta{}, fmt.Errorf("real output not found in ring")
|
||||
return types.TxInputToKey{}, inputMeta{}, errors.New("real output not found in ring")
|
||||
}
|
||||
|
||||
// Build key offsets and public key list.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package wallet
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"strings"
|
||||
|
|
@ -43,7 +44,7 @@ func MnemonicDecode(phrase string) ([32]byte, error) {
|
|||
|
||||
expected := checksumIndex(words[:24])
|
||||
if words[24] != words[expected] {
|
||||
return key, fmt.Errorf("wallet: mnemonic checksum failed")
|
||||
return key, errors.New("wallet: mnemonic checksum failed")
|
||||
}
|
||||
|
||||
n := uint32(numWords)
|
||||
|
|
|
|||
|
|
@ -10,15 +10,16 @@
|
|||
package wallet
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
store "forge.lthn.ai/core/go-store"
|
||||
"forge.lthn.ai/core/go-blockchain/chain"
|
||||
"forge.lthn.ai/core/go-blockchain/rpc"
|
||||
"forge.lthn.ai/core/go-blockchain/types"
|
||||
"forge.lthn.ai/core/go-blockchain/wire"
|
||||
store "forge.lthn.ai/core/go-store"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -165,7 +166,7 @@ func (w *Wallet) Balance() (confirmed, locked uint64, err error) {
|
|||
// Send constructs and submits a transaction.
|
||||
func (w *Wallet) Send(destinations []Destination, fee uint64) (*types.Transaction, error) {
|
||||
if w.builder == nil || w.client == nil {
|
||||
return nil, fmt.Errorf("wallet: no RPC client configured")
|
||||
return nil, errors.New("wallet: no RPC client configured")
|
||||
}
|
||||
|
||||
chainHeight, err := w.chain.Height()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue