Skip to content

Commit a21efde

Browse files
authored
Merge pull request #713 from lightninglabs/err_shadowing_fixes
rpcserver+tapscript: err shadowing fixes
2 parents bb38de7 + d6b10be commit a21efde

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

rpcserver.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,6 @@ func (r *rpcServer) QueryAddrs(ctx context.Context,
10501050
func (r *rpcServer) NewAddr(ctx context.Context,
10511051
req *taprpc.NewAddrRequest) (*taprpc.Addr, error) {
10521052

1053-
var err error
1054-
10551053
// Parse the proof courier address if one was provided, otherwise use
10561054
// the default specified in the config.
10571055
courierAddr := r.cfg.DefaultProofCourierAddr
@@ -1089,7 +1087,7 @@ func (r *rpcServer) NewAddr(ctx context.Context,
10891087
rpcsLog.Infof("[NewAddr]: making new addr: asset_id=%x, amt=%v",
10901088
assetID[:], req.Amt)
10911089

1092-
err = r.checkBalanceOverflow(ctx, &assetID, nil, req.Amt)
1090+
err := r.checkBalanceOverflow(ctx, &assetID, nil, req.Amt)
10931091
if err != nil {
10941092
return nil, err
10951093
}
@@ -1376,7 +1374,7 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
13761374
var exclusionProofs [][]byte
13771375
for _, exclusionProof := range p.ExclusionProofs {
13781376
var exclusionProofBuf bytes.Buffer
1379-
err := exclusionProof.Encode(&exclusionProofBuf)
1377+
err = exclusionProof.Encode(&exclusionProofBuf)
13801378
if err != nil {
13811379
return nil, fmt.Errorf("unable to encode exclusion "+
13821380
"proofs: %w", err)
@@ -1388,7 +1386,7 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
13881386

13891387
var splitRootProofBuf bytes.Buffer
13901388
if splitRootProof != nil {
1391-
err := splitRootProof.Encode(&splitRootProofBuf)
1389+
err = splitRootProof.Encode(&splitRootProofBuf)
13921390
if err != nil {
13931391
return nil, fmt.Errorf("unable to encode split root "+
13941392
"proof: %w", err)
@@ -3140,7 +3138,7 @@ func (r *rpcServer) QueryAssetRoots(ctx context.Context,
31403138

31413139
// Check the rate limiter to see if we need to wait at all. If not then
31423140
// this'll be a noop.
3143-
if err := r.proofQueryRateLimiter.Wait(ctx); err != nil {
3141+
if err = r.proofQueryRateLimiter.Wait(ctx); err != nil {
31443142
return nil, err
31453143
}
31463144

@@ -3193,7 +3191,7 @@ func (r *rpcServer) QueryAssetRoots(ctx context.Context,
31933191
foundGroupKey.SerializeCompressed(),
31943192
groupedAssetID.String())
31953193

3196-
assetRoots, err := r.queryAssetProofRoots(ctx, groupUniID)
3194+
assetRoots, err = r.queryAssetProofRoots(ctx, groupUniID)
31973195
if err != nil {
31983196
return nil, err
31993197
}
@@ -3273,7 +3271,7 @@ func (r *rpcServer) DeleteAssetRoot(ctx context.Context,
32733271
// issuance and transfer roots.
32743272
if universeID.ProofType == universe.ProofTypeUnspecified {
32753273
universeID.ProofType = universe.ProofTypeIssuance
3276-
_, err := r.cfg.UniverseArchive.DeleteRoot(ctx, universeID)
3274+
_, err = r.cfg.UniverseArchive.DeleteRoot(ctx, universeID)
32773275
if err != nil {
32783276
return nil, err
32793277
}
@@ -3339,7 +3337,7 @@ func (r *rpcServer) AssetLeafKeys(ctx context.Context,
33393337

33403338
// Check the rate limiter to see if we need to wait at all. If not then
33413339
// this'll be a noop.
3342-
if err := r.proofQueryRateLimiter.Wait(ctx); err != nil {
3340+
if err = r.proofQueryRateLimiter.Wait(ctx); err != nil {
33433341
return nil, err
33443342
}
33453343

@@ -3404,7 +3402,7 @@ func (r *rpcServer) AssetLeaves(ctx context.Context,
34043402

34053403
// Check the rate limiter to see if we need to wait at all. If not then
34063404
// this'll be a noop.
3407-
if err := r.proofQueryRateLimiter.Wait(ctx); err != nil {
3405+
if err = r.proofQueryRateLimiter.Wait(ctx); err != nil {
34083406
return nil, err
34093407
}
34103408

@@ -3458,35 +3456,32 @@ func UnmarshalOutpoint(outpoint string) (*wire.OutPoint, error) {
34583456

34593457
// unmarshalLeafKey un-marshals a leaf key from the RPC form.
34603458
func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) {
3461-
var (
3462-
leafKey universe.LeafKey
3463-
err error
3464-
)
3459+
var leafKey universe.LeafKey
34653460

34663461
switch {
34673462
case key.GetScriptKeyBytes() != nil:
3468-
pubKey, err := parseUserKey(key.GetScriptKeyBytes())
3463+
scriptKey, err := parseUserKey(key.GetScriptKeyBytes())
34693464
if err != nil {
34703465
return leafKey, err
34713466
}
34723467

34733468
leafKey.ScriptKey = &asset.ScriptKey{
3474-
PubKey: pubKey,
3469+
PubKey: scriptKey,
34753470
}
34763471

34773472
case key.GetScriptKeyStr() != "":
3478-
scriptKeyBytes, sErr := hex.DecodeString(key.GetScriptKeyStr())
3479-
if sErr != nil {
3473+
scriptKeyBytes, err := hex.DecodeString(key.GetScriptKeyStr())
3474+
if err != nil {
34803475
return leafKey, err
34813476
}
34823477

3483-
pubKey, err := parseUserKey(scriptKeyBytes)
3478+
scriptKey, err := parseUserKey(scriptKeyBytes)
34843479
if err != nil {
34853480
return leafKey, err
34863481
}
34873482

34883483
leafKey.ScriptKey = &asset.ScriptKey{
3489-
PubKey: pubKey,
3484+
PubKey: scriptKey,
34903485
}
34913486
default:
34923487
// TODO(roasbeef): can actually allow not to be, then would
@@ -3520,7 +3515,7 @@ func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) {
35203515
}
35213516

35223517
default:
3523-
return leafKey, fmt.Errorf("outpoint not set: %v", err)
3518+
return leafKey, fmt.Errorf("outpoint not set")
35243519
}
35253520

35263521
return leafKey, nil
@@ -3647,7 +3642,7 @@ func (r *rpcServer) QueryProof(ctx context.Context,
36473642

36483643
// Check the rate limiter to see if we need to wait at all. If not then
36493644
// this'll be a noop.
3650-
if err := r.proofQueryRateLimiter.Wait(ctx); err != nil {
3645+
if err = r.proofQueryRateLimiter.Wait(ctx); err != nil {
36513646
return nil, err
36523647
}
36533648

@@ -3772,7 +3767,7 @@ func (r *rpcServer) InsertProof(ctx context.Context,
37723767

37733768
// Check the rate limiter to see if we need to wait at all. If not then
37743769
// this'll be a noop.
3775-
if err := r.proofQueryRateLimiter.Wait(ctx); err != nil {
3770+
if err = r.proofQueryRateLimiter.Wait(ctx); err != nil {
37763771
return nil, err
37773772
}
37783773

tapscript/send.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ func CreateOutputCommitments(inputTapCommitments tappsbt.InputCommitments,
794794
}
795795

796796
// Remove all input assets from the asset commitment tree.
797-
err := assetCommitment.Delete(inputAsset)
797+
err = assetCommitment.Delete(inputAsset)
798798
if err != nil {
799799
return nil, err
800800
}
@@ -819,7 +819,7 @@ func CreateOutputCommitments(inputTapCommitments tappsbt.InputCommitments,
819819
// The asset is present, just commit it to the input
820820
// asset commitment.
821821
case vOut.Asset != nil:
822-
err := assetCommitment.Upsert(vOut.Asset)
822+
err = assetCommitment.Upsert(vOut.Asset)
823823
if err != nil {
824824
return nil, err
825825
}

0 commit comments

Comments
 (0)