Skip to content

Commit dfda0dc

Browse files
committed
Moved the reveal chain validation from entry.go to processor. #676
1 parent 5bcd1db commit dfda0dc

3 files changed

Lines changed: 6 additions & 19 deletions

File tree

common/entry.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ func NewEntry() *Entry {
3737
return e
3838
}
3939

40-
func ValidateRevealEntryChainID(e *Entry) error {
41-
if e == nil {
42-
return fmt.Errorf("No entry provided")
43-
}
44-
expectedChainID := NewChainID(e)
45-
if !expectedChainID.IsSameAs(e.ChainID) {
46-
return fmt.Errorf("Invalid ChainID.")
47-
}
48-
return nil
49-
}
50-
5140
// NewChainID generates a ChainID from an entry. ChainID = Sha(Sha(ExtIDs[0]) +
5241
// Sha(ExtIDs[1] + ... + Sha(ExtIDs[n]))
5342
func NewChainID(e *Entry) *Hash {

process/processor.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ func processRevealEntry(msg *wire.MsgRevealEntry) error {
566566
fMemPool.addOrphanMsg(msg, h)
567567
return fmt.Errorf("Credit needs to paid first before an entry is revealed: %s", e.Hash().String())
568568
}
569+
570+
//validate chain id for the first entry
571+
expectedChainID := common.NewChainID(e)
572+
if !expectedChainID.IsSameAs(e.ChainID) {
573+
return fmt.Errorf("Invalid ChainID for entry: %s", e.Hash().String())
574+
}
569575

570576
//validate chainid hash in the commitChain
571577
chainIDHash := common.DoubleSha(e.ChainID.Bytes())

wsapi/wsapi.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,6 @@ func handleRevealEntry(ctx *web.Context) {
201201
}
202202
}
203203

204-
err := common.ValidateRevealEntryChainID(entry)
205-
if err != nil {
206-
wsLog.Error(err)
207-
ctx.WriteHeader(httpBad)
208-
ctx.Write([]byte(err.Error()))
209-
return
210-
}
211-
212204
if err := factomapi.RevealEntry(entry); err != nil {
213205
wsLog.Error(err)
214206
ctx.WriteHeader(httpBad)

0 commit comments

Comments
 (0)