github.com/ledgerwatch/erigon-lib@v1.0.0/bptree/felt.go (about) 1 /* 2 Copyright 2022 Erigon contributors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package bptree 18 19 import ( 20 "crypto/sha256" 21 "encoding/binary" 22 ) 23 24 type Felt uint64 25 26 func (v *Felt) Binary() []byte { 27 b := make([]byte, 8) 28 binary.BigEndian.PutUint64(b, uint64(*v)) 29 return b 30 } 31 32 func hash2(bytes1, bytes2 []byte) []byte { 33 hashBuilder := sha256.New() 34 bytes1Written, _ := hashBuilder.Write(bytes1) 35 ensure(bytes1Written == len(bytes1), "hash2: invalid number of bytes1 written") 36 bytes2Written, _ := hashBuilder.Write(bytes2) 37 ensure(bytes2Written == len(bytes2), "hash2: invalid number of bytes2 written") 38 return hashBuilder.Sum(nil) 39 } 40 41 func deref(pointers []*Felt) []Felt { 42 pointees := make([]Felt, 0) 43 for _, ptr := range pointers { 44 if ptr != nil { 45 pointees = append(pointees, *ptr) 46 } else { 47 break 48 } 49 } 50 return pointees 51 }