internal Key(Endorsement endorsement) : this() { switch (endorsement.Type) { case KeyType.Ed25519: Ed25519 = ByteString.CopyFrom(((Ed25519PublicKeyParameters)endorsement._data).GetEncoded()); break; case KeyType.RSA3072: RSA3072 = ByteString.CopyFrom(((ReadOnlyMemory <byte>)endorsement._data).ToArray()); break; case KeyType.ECDSA384: ECDSA384 = ByteString.CopyFrom(((ReadOnlyMemory <byte>)endorsement._data).ToArray()); break; case KeyType.Contract: ContractID = new ContractID((Address)Abi.DecodeAddressPart((ReadOnlyMemory <byte>)endorsement._data)); break; case KeyType.List: ThresholdKey = new ThresholdKey { Threshold = endorsement.RequiredCount, Keys = new KeyList((Endorsement[])endorsement._data) }; break; default: throw new InvalidOperationException("Endorsement is Empty."); } }
public void CanCreateContractEndorsementFromProtobufContractKeyType() { var contract = new Address(Generator.Integer(0, 100), Generator.Integer(0, 100), Generator.Integer(1000, 20000)); var contractID = new Proto.ContractID(contract); var key = new Proto.Key { ContractID = contractID }; var endorsement = key.ToEndorsement(); var decoded = Abi.DecodeAddressPart(endorsement.PublicKey); Assert.Equal(KeyType.Contract, endorsement.Type); Assert.Empty(endorsement.List); Assert.Equal(0U, endorsement.RequiredCount); Assert.Equal(contract, decoded); }