Skip to content

Commit

Permalink
feat: added GetScheduleSignatures() to schedule_create_transaction an…
Browse files Browse the repository at this point in the history
…d schedule_sign_transaction
  • Loading branch information
andrix10 committed Mar 1, 2021
1 parent 5e2bed4 commit 6f34fd0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
23 changes: 23 additions & 0 deletions schedule_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ func (builder ScheduleCreateTransaction) SetAdminKey(key PublicKey) ScheduleCrea
return builder
}

func (builder *ScheduleCreateTransaction) GetScheduleSignatures() (map[*Ed25519PublicKey][]byte, error) {
signMap := make(map[*Ed25519PublicKey][]byte, len(builder.pb.GetSigMap().GetSigPair()))

for _, sigPair := range builder.pb.GetSigMap().GetSigPair() {
key, err := Ed25519PublicKeyFromBytes(sigPair.PubKeyPrefix)
if err != nil {
return make(map[*Ed25519PublicKey][]byte, 0), err
}
switch sigPair.Signature.(type) {
case *proto.SignaturePair_Contract:
signMap[&key] = sigPair.GetContract()
case *proto.SignaturePair_Ed25519:
signMap[&key] = sigPair.GetEd25519()
case *proto.SignaturePair_RSA_3072:
signMap[&key] = sigPair.GetRSA_3072()
case *proto.SignaturePair_ECDSA_384:
signMap[&key] = sigPair.GetECDSA_384()
}
}

return signMap, nil
}

//
// The following methods must be copy-pasted/overriden at the bottom of **every** _transaction.go file
// We override the embedded fluent setter methods to return the outer type
Expand Down
33 changes: 26 additions & 7 deletions schedule_sign_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ func NewScheduleSignTransaction() ScheduleSignTransaction {
}

func (builder ScheduleSignTransaction) AddScheduleSignature(key Ed25519PublicKey, signature []byte) ScheduleSignTransaction {
var sigPair proto.SignaturePair

sigPair.PubKeyPrefix = key.Bytes()

switch sig := sigPair.Signature.(type) {
case *proto.SignaturePair_Ed25519:
sig.Ed25519 = signature
sigPair := proto.SignaturePair{
PubKeyPrefix: key.keyData,
Signature: &proto.SignaturePair_Ed25519{Ed25519: signature},
}

if builder.pb.SigMap != nil {
Expand All @@ -54,6 +50,29 @@ func (builder ScheduleSignTransaction) SetScheduleID(id ScheduleID) ScheduleSign
return builder
}

func (builder *ScheduleSignTransaction) GetScheduleSignatures() (map[*Ed25519PublicKey][]byte, error) {
signMap := make(map[*Ed25519PublicKey][]byte, len(builder.pb.GetSigMap().GetSigPair()))

for _, sigPair := range builder.pb.GetSigMap().GetSigPair() {
key, err := Ed25519PublicKeyFromBytes(sigPair.PubKeyPrefix)
if err != nil {
return make(map[*Ed25519PublicKey][]byte, 0), err
}
switch sigPair.Signature.(type) {
case *proto.SignaturePair_Contract:
signMap[&key] = sigPair.GetContract()
case *proto.SignaturePair_Ed25519:
signMap[&key] = sigPair.GetEd25519()
case *proto.SignaturePair_RSA_3072:
signMap[&key] = sigPair.GetRSA_3072()
case *proto.SignaturePair_ECDSA_384:
signMap[&key] = sigPair.GetECDSA_384()
}
}

return signMap, nil
}

//
// The following methods must be copy-pasted/overriden at the bottom of **every** _transaction.go file
// We override the embedded fluent setter methods to return the outer type
Expand Down

0 comments on commit 6f34fd0

Please sign in to comment.