示例#1
0
func (service *TransactionService) GetTransaction(r *http.Request, args *GetTransactionArgs, reply *GetTransactionReply) error {
	hash, err := hex.DecodeString(args.Hash)
	if err != nil {
		return err
	}
	var tx *transaction.Envelope

	tx, err = service.srv.DB.GetTransaction(hash)
	if err != nil {
		return err
	}

	if tx == nil {
		block, err := service.srv.DB.GetTransactionBlock(hash)
		if err != nil {
			return err
		}
		for i := range block.Transactions {
			if block.Transactions[i].Hash().Equals(hash) {
				tx = block.Transactions[i]
				break
			}
		}
	}
	if tx == nil {
		return err
	}
	reply.PreviousTransactionHash = hex.EncodeToString(tx.PreviousEnvelopeHash)
	pk, err := keys.DecodeECDSAPublicKey(tx.PublicKey)
	if err != nil {
		return err
	}
	reply.PublicKey = keys.ECDSAPublicKeyToString(*pk)
	pk, err = keys.DecodeECDSAPublicKey(tx.PublicKey)
	if err != nil {
		return err
	}
	reply.NextPublicKey = keys.ECDSAPublicKeyToString(*pk)
	reply.Valid = tx.Transaction.Valid()
	jsonEncoded, err := json.Marshal(tx.Transaction)
	if err != nil {
		return err
	}
	reply.Content = string(jsonEncoded)
	return nil
}
示例#2
0
文件: nrt.go 项目: prodigeni/gitchain
func NewNameReservation(name string, publicKey *ecdsa.PublicKey) (txn *NameReservation, random []byte) {
	buf := make([]byte, 4)
	rand.Read(buf)
	return &NameReservation{
			Version:   NAME_RESERVATION_VERSION,
			Hashed:    fastsha256.Sum256(append([]byte(name), buf...)),
			PublicKey: []byte(keys.ECDSAPublicKeyToString(*publicKey))},
		buf
}
示例#3
0
func (srv *KeyService) GeneratePrivateKey(r *http.Request, args *GeneratePrivateKeyArgs, reply *GeneratePrivateKeyReply) error {
	key, err := keys.GenerateECDSA()
	if err != nil {
		reply.Success = false
		return err
	}
	err = env.DB.PutKey(args.Alias, key, false)
	if err != nil {
		reply.Success = false
		return err
	}
	reply.PublicKey = keys.ECDSAPublicKeyToString(key.PublicKey)
	reply.Success = true
	return nil
}