Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7569f88

Browse files
committed
Made receipts generate when there isn't an anchor.
1 parent 43b1243 commit 7569f88

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

receipts/receipts.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,12 @@ func CreateReceipt(dbo interfaces.DBOverlay, entryID interfaces.IHash) (*Receipt
392392
return nil, err
393393
}
394394

395-
if dirBlockInfo == nil {
396-
return nil, fmt.Errorf("dirBlockInfo not found")
397-
}
398-
dbi := dirBlockInfo.(*dbInfo.DirBlockInfo)
395+
if dirBlockInfo != nil {
396+
dbi := dirBlockInfo.(*dbInfo.DirBlockInfo)
399397

400-
receipt.BitcoinTransactionHash = dbi.BTCTxHash.(*primitives.Hash)
401-
receipt.BitcoinBlockHash = dbi.BTCBlockHash.(*primitives.Hash)
398+
receipt.BitcoinTransactionHash = dbi.BTCTxHash.(*primitives.Hash)
399+
receipt.BitcoinBlockHash = dbi.BTCBlockHash.(*primitives.Hash)
400+
}
402401

403402
return receipt, nil
404403
}

wsapi/wsapi_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,32 @@ func TestHandleGetReceipt(t *testing.T) {
440440
t.Error(err)
441441
}
442442
}
443+
444+
func TestHandleGetUnanchoredReceipt(t *testing.T) {
445+
context := testHelper.CreateWebContext()
446+
hash := "68a503bd3d5b87d3a41a737e430d2ce78f5e556f6a9269859eeb1e053b7f92f7"
447+
448+
HandleGetReceipt(context, hash)
449+
450+
j := testHelper.GetRespMap(context)
451+
452+
if j == nil {
453+
t.Error("Receipt not found!")
454+
return
455+
}
456+
457+
dbo := context.Server.Env["state"].(interfaces.IState).GetAndLockDB()
458+
defer context.Server.Env["state"].(interfaces.IState).UnlockDB()
459+
460+
receipt := j["receipt"].(map[string]interface{})
461+
marshalled, err := json.Marshal(receipt)
462+
if err != nil {
463+
t.Error(err)
464+
}
465+
466+
err = receipts.VerifyFullReceipt(dbo, string(marshalled))
467+
if err != nil {
468+
t.Logf("receipt - %v", j)
469+
t.Error(err)
470+
}
471+
}

0 commit comments

Comments
 (0)