Skip to content

Commit a83b6fd

Browse files
author
nisdas
committed
sharding/client: Changing Validate Body(ethereum#92)
1 parent 0ac53e8 commit a83b6fd

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

sharding/client/utils.go

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,64 @@ import (
77
type collationbody []byte
88

99
var (
10-
collationsizelimit = int64(2 * *20)
10+
collationsizelimit = int64(2 ^ 20)
1111
chunkSize = int64(32)
1212
indicatorSize = int64(1)
1313
chunkDataSize = chunkSize - indicatorSize
1414
)
1515

16-
func (c *collationbody) validateBody() bool {
17-
return len(c) < 2^20 && len(c) > 0
16+
/* Validate that the collation body is within its bounds and if
17+
the size of the body is below the limit it is simply appended
18+
till it reaches the required limit */
19+
20+
func (cb collationbody) validateBody() error {
21+
22+
length := int64(len(cb))
23+
24+
if length == 0 {
25+
return fmt.Errorf("Collation Body has to be a non-zero value")
26+
}
27+
28+
if length > collationsizelimit {
29+
return fmt.Errorf("Collation Body is over the size limit")
30+
}
31+
32+
if length < collationsizelimit {
33+
x := make([]byte, (collationsizelimit - length))
34+
cb = append(cb, x...)
35+
fmt.Printf("%b", x)
36+
37+
}
38+
39+
return nil
40+
}
41+
42+
func main() {
43+
44+
x := []byte{'h', 'e', 'g', 'g'}
45+
t := x.validateBody()
46+
fmt.Printf("%b %s", x, t)
47+
1848
}
1949

20-
func createChunks(c collationbody) {
21-
validCollation, err := c.validateBody
50+
/*
51+
func createChunks(cb collationbody) {
52+
validCollation := cb.validateBody
2253
if err != nil {
2354
fmt.Errorf("Error %v", err)
2455
}
2556
if !validCollation {
2657
fmt.Errorf("Error %v", err)
2758
}
28-
index := int64(len(c)) / chunkDataSize
59+
index := int64(len(cb)) / chunkDataSize
60+
2961
30-
/*
3162
for i = 0; i < index; i++ {
3263
serialisedblob[i*chunksize] = 0
3364
for f = 0; f <chunkdatasize ; f++ {
3465
serialisedblob[(f+1) + i*chunksize] = collationbody[f + i*chunkdatasize]
3566
}
3667
serialisedblob[index*chunksize ] = len(collationbody) – index*chunkdatasize
37-
}*/
68+
}
3869
39-
}
70+
} */

0 commit comments

Comments
 (0)