Пример #1
0
        public byte[] BuildTx(string[] command, out string msg)
        {
            if (command.Length == 0)
            {
                msg = "Expecting a creditcoin command";
                return(null);
            }

            var map = CBORObject.NewMap();

            map.Add("v", command[0]); // verb

            for (int i = 1; i < command.Length; ++i)
            {
                map.Add("p" + i.ToString(), command[i]); // params
            }

            var pubKeyHexStr = mSigner.GetPublicKey().ToHexString();
            var settings     = new EncoderSettings()
            {
                BatcherPublicKey = pubKeyHexStr,
                SignerPublickey  = pubKeyHexStr,
                FamilyName       = CREDITCOIN,
                FamilyVersion    = version
            };

            settings.Inputs.Add(prefix);
            settings.Outputs.Add(prefix);
            var encoder = new Encoder(settings, mSigner.GetPrivateKey());

            msg = null;
            return(encoder.EncodeSingleTransaction(map.EncodeToBytes()));
        }
Пример #2
0
        public resData postMedicalRecord(string userId, string verb, string value)
        {
            var obj = CBORObject.NewMap()
                      .Add("Name", userId)
                      .Add("Verb", verb)
                      .Add("Value", value);
            var prefix = "intkey".ToByteArray().ToSha512().ToHexString().Substring(0, 6);
            var signer = new Signer();

            var settings = new EncoderSettings()
            {
                BatcherPublicKey = signer.GetPublicKey().ToHexString(),
                SignerPublickey  = signer.GetPublicKey().ToHexString(),
                FamilyName       = "intkey",
                FamilyVersion    = "1.0"
            };

            settings.Inputs.Add(prefix);
            settings.Outputs.Add(prefix);
            var encoder = new Sawtooth.Sdk.Client.Encoder(settings, signer.GetPrivateKey());

            var payload = encoder.EncodeSingleTransaction(obj.EncodeToBytes());
            //var payload = obj.EncodeToBytes();

            var content = new ByteArrayContent(payload);

            content.Headers.Add("Content-Type", "application/octet-stream");

            var httpClient = new HttpClient();

            var response = httpClient.PostAsync("http://localhost:8008/batches", content).Result;

            return(new resData()
            {
                response = response, encoderSettings = settings, obj = obj
            });
        }