コード例 #1
0
func TestValidateAnchorRecord(t *testing.T) {
	pub := new(primitives.PublicKey)
	err := pub.UnmarshalText([]byte("0426a802617848d4d16d87830fc521f4d136bb2d0c352850919c2679f189613a"))
	if err != nil {
		t.Error(err)
	}
	signedRecord := `{"AnchorRecordVer":1,"DBHeight":46226,"KeyMR":"831287d96f9955ff438836b26219b8c937e01e668295e8334a5d140cdaacd2fd","RecordHeight":46226,"Bitcoin":{"Address":"1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF","TXID":"9a47f131677e135645cebe74085cd980044eda2abbb05ac09ee79ba8640f368d","BlockHeight":421417,"BlockHash":"000000000000000003781bf1b36dbaa1a71f94e23b4b9dc13024379aaf244d89","Offset":599}}e5d40b8673fbeba9e4e5a4322a514ec28989acef55b6fcdf49eae400b6d302852c2cf6659dc1f3298ffae60f6605666efbcef3ac4947333515084e1269ec0807`

	ar, valid, err := UnmarshalAndValidateAnchorRecord([]byte(signedRecord), pub)
	if err != nil {
		t.Error(err)
	}
	if valid != true {
		t.Errorf("Anchor record is not valid")
	}
	if ar == nil {
		t.Errorf("No anchor record returned!")
	}

	invalidRecord := `{"AnchorRecordVer":1,"DBHeight":46226,"KeyMR":"831287d96f9955ff438836b26219b8c937e01e668295e8334a5d140cdaacd2fd","RecordHeight":46226,"Bitcoin":{"Address":"1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF","TXID":"9a47f131677e135645cebe74085cd980044eda2abbb05ac09ee79ba8640f368d","BlockHeight":421417,"BlockHash":"000000000000000003781bf1b36dbaa1a71f94e23b4b9dc13024379aaf244d89","Offset":599}}e5d40b8673fbeba9e4e5a4322a514ec28989acef55b6fcdf49eae400b6d302852c2cf6659dc1f3298ffae60f6605666efbcef3ac4947333515084e1269ec0806`

	ar, valid, err = UnmarshalAndValidateAnchorRecord([]byte(invalidRecord), pub)
	if err != nil {
		t.Error(err)
	}
	if valid != false {
		t.Errorf("Anchor record is valid when it shouldn't be")
	}
	if ar != nil {
		t.Errorf("Anchor record returned when it shouldn't be!")
	}
}
コード例 #2
0
ファイル: adminBlock.go プロジェクト: FactomProject/factomd
func (c *AdminBlock) AddFederatedServerSigningKey(identityChainID interfaces.IHash, publicKey *[32]byte) error {
	p := new(primitives.PublicKey)
	err := p.UnmarshalBinary(publicKey[:])
	if err != nil {
		return err
	}
	entry := NewAddFederatedServerSigningKey(identityChainID, byte(0), *p, c.Header.GetDBHeight()+1)
	c.AddEntry(entry)
	return nil
}