more streamlined json output for the goldilocks field (4 field elements per line)
This commit is contained in:
parent
14bab04b19
commit
1c51aca81b
|
@ -10,5 +10,5 @@ bin = @["cli"]
|
|||
requires "nim >= 1.6.0"
|
||||
requires "https://github.com/mratsim/constantine#ab6fa6ae1bbbd1b10071a92ec209b381b5d82511"
|
||||
requires "https://github.com/codex-storage/nim-poseidon2#8a54c69032a741160bbc097d009e45a8b5e4d718"
|
||||
requires "https://github.com/codex-storage/nim-goldilocks-hash#0d12b1429345c3f359df47171332e8966dc94ed3"
|
||||
#requires "../../../../nim-goldilocks-hash/"
|
||||
requires "https://github.com/codex-storage/nim-goldilocks-hash#bd5b805b80b6005a3e5de412dec15783284d205d"
|
||||
#requires "goldilocks_hash == 0.0.1"
|
||||
|
|
|
@ -17,7 +17,7 @@ import shared
|
|||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc writeFieldElems(h: Stream, prefix: string, xs: seq[F]) =
|
||||
writeList[F]( h, prefix, xs, writeF )
|
||||
writeList[F]( h, prefix, xs, writeLnF )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -20,16 +20,23 @@ func bytesToFieldElements( bytes: openArray[byte] ): seq[F] =
|
|||
let digests = padAndDecodeBytesToDigest62(bytes)
|
||||
return digestSeqToFeltSeq(digests)
|
||||
|
||||
func bytesToFieldElementsMat( bytes: openArray[byte] ): seq[seq[F]] =
|
||||
let digests = padAndDecodeBytesToDigest62(bytes)
|
||||
return digestSeqToFeltSeqSeq(digests)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc writeFieldElems(h: Stream, prefix: string, xs: seq[F]) =
|
||||
writeList[F]( h, prefix, xs, writeF )
|
||||
writeList[F]( h, prefix, xs, writeLnF )
|
||||
|
||||
proc writeFieldElemsMat(h: Stream, prefix: string, xs: seq[seq[F]]) =
|
||||
writeListList[F]( h, prefix, xs, writeF )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc writeSingleCellData(h: Stream, prefix:string , cell: Cell) =
|
||||
let flds : seq[F] = bytesToFieldElements(cell) # cell.elements(F).toSeq()
|
||||
writeFieldElems(h, prefix, flds)
|
||||
let flds : seq[seq[F]] = bytesToFieldElementsMat(cell)
|
||||
writeFieldElemsMat(h, prefix, flds)
|
||||
|
||||
proc writeAllCellData(h: Stream, cells: seq[Cell]) =
|
||||
writeList(h, " ", cells, writeSingleCellData )
|
||||
|
@ -37,8 +44,8 @@ proc writeAllCellData(h: Stream, cells: seq[Cell]) =
|
|||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc writeSingleMerklePath(h: Stream, prefix: string, path: MerkleProof[Digest]) =
|
||||
let flds : seq[F] = digestSeqToFeltSeq( path.merklePath )
|
||||
writeFieldElems(h, prefix, flds)
|
||||
let flds : seq[seq[F]] = digestSeqToFeltSeqSeq( path.merklePath )
|
||||
writeFieldElemsMat(h, prefix, flds)
|
||||
|
||||
proc writeAllMerklePaths(h: Stream, paths: seq[MerkleProof[Digest]]) =
|
||||
writeList(h, " ", paths, writeSingleMerklePath )
|
||||
|
|
|
@ -24,4 +24,27 @@ proc writeList*[T](h: Stream, prefix: string, xs: seq[T], writeFun: WriteFun[T])
|
|||
writeFun(h, indent & ", ", xs[i])
|
||||
h.writeLine( indent & "]" )
|
||||
|
||||
#---------------------------------------
|
||||
|
||||
proc writeListList*[T](h: Stream, prefix: string, xs: seq[seq[T]], writeFun: WriteFun[T]) =
|
||||
let n = xs.len
|
||||
let indent = mkIndent(prefix)
|
||||
for i in 0..<n:
|
||||
|
||||
if i==0:
|
||||
h.write( prefix & "[ ")
|
||||
else:
|
||||
h.write( indent & ", ")
|
||||
|
||||
let ys = xs[i]
|
||||
let m = ys.len
|
||||
for j in 0..<m:
|
||||
if j==0:
|
||||
writeFun(h, "" , ys[j])
|
||||
else:
|
||||
writeFun(h, " , ", ys[j])
|
||||
|
||||
h.write("\n")
|
||||
h.writeLine( indent & "]" )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
|
|
@ -36,9 +36,12 @@ func toQuotedDecimalF*(x: F): string =
|
|||
let s : string = toDecimalF(x)
|
||||
return ("\"" & s & "\"")
|
||||
|
||||
proc writeF*(h: Stream, prefix: string, x: F) =
|
||||
proc writeLnF*(h: Stream, prefix: string, x: F) =
|
||||
h.writeLine(prefix & toQuotedDecimalF(x))
|
||||
|
||||
proc writeF*(h: Stream, prefix: string, x: F) =
|
||||
h.write(prefix & toQuotedDecimalF(x))
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
func extractLowBits[n: static int]( A: BigInt[n], k: int): uint64 =
|
||||
|
|
|
@ -23,9 +23,12 @@ func toQuotedDecimalF*(x: F): string =
|
|||
let s : string = toDecimalF(x)
|
||||
return ("\"" & s & "\"")
|
||||
|
||||
proc writeF*(h: Stream, prefix: string, x: F) =
|
||||
proc writeLnF*(h: Stream, prefix: string, x: F) =
|
||||
h.writeLine(prefix & toQuotedDecimalF(x))
|
||||
|
||||
proc writeF*(h: Stream, prefix: string, x: F) =
|
||||
h.write(prefix & toQuotedDecimalF(x))
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
func extractLowBits*(fld: F, k: int): uint64 =
|
||||
|
@ -38,7 +41,9 @@ func extractLowBits*(fld: F, k: int): uint64 =
|
|||
|
||||
func digestToJsonString*( d: Digest ): string =
|
||||
let xs: F4 = fromDigest(d)
|
||||
return "[ " & toDecimalF(xs[0]) & ", " &
|
||||
toDecimalF(xs[1]) & ", " &
|
||||
toDecimalF(xs[2]) & ", " &
|
||||
toDecimalF(xs[3]) & " ]"
|
||||
return "[ " & toQuotedDecimalF(xs[0]) & ", " &
|
||||
toQuotedDecimalF(xs[1]) & ", " &
|
||||
toQuotedDecimalF(xs[2]) & ", " &
|
||||
toQuotedDecimalF(xs[3]) & " ]"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue