MCPcopy Create free account
hub / github.com/chain/txvm / sign

Function sign

cmd/block/block.go:154–190  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

152}
153
154func sign(args []string) {
155 fs := flag.NewFlagSet("sign", flag.PanicOnError)
156 prevHex := fs.String("prev", "", "previous block header (hex)")
157 err := fs.Parse(args)
158 must(err)
159
160 prevBytes, err := hex.DecodeString(*prevHex)
161 must(err)
162
163 var prev bc.BlockHeader
164 err = proto.Unmarshal(prevBytes, &prev)
165 must(err)
166
167 blockBytes, err := ioutil.ReadAll(os.Stdin)
168 must(err)
169
170 block := new(bc.Block)
171 err = block.FromBytes(blockBytes)
172 must(err)
173
174 hash := block.Hash().Bytes()
175
176 block, err = bc.SignBlock(block.UnsignedBlock, &prev, func(idx int) (interface{}, error) {
177 if arg := fs.Arg(idx); arg != "" {
178 prv, err := hex.DecodeString(arg)
179 must(err)
180 return ed25519.Sign(prv, hash), nil
181 }
182 return nil, nil
183 })
184 must(err)
185
186 blockBytes, err = block.Bytes()
187 must(err)
188
189 os.Stdout.Write(blockBytes)
190}
191
192func validate(args []string) {
193 fs := flag.NewFlagSet("validate", flag.PanicOnError)

Callers

nothing calls this directly

Calls 8

SignBlockFunction · 0.92
SignFunction · 0.92
mustFunction · 0.70
StringMethod · 0.65
FromBytesMethod · 0.45
BytesMethod · 0.45
HashMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected