public byte[] GetMarshalBinary()
        {
            var byteList = new List <byte>();

            //1 byte version
            byteList.Add(2);

            // 6 byte milliTimestamp (truncated unix time)
            byteList.AddRange(FactomUtils.MilliTime());


            // 1 byte Input Count. This is how many Factoid addresses are being spent from in this transaction.
            byteList.Add((byte)FCT_Input.Count);
            // 1 byte Factoid Output Count. This is how many Factoid addresses are being spent to in this transaction.
            byteList.Add((byte)FCT_Output.Count);
            // 1 byte Entry Credit Purchase Count. This is how many Entry Credit addresses are being spent to in this transaction.
            byteList.Add((byte)EC_Output.Count);

            //INPUTS

            // varInt_F (Input X) This is how much the Factoshi balance of Input X will be decreased by.
            // 32 bytes Factoid Address (Input X) This is an RCD hash which previously had value assigned to it.
            foreach (var fct in FCT_Input)
            {
                if (fct.Key == FCT_Input.First().Key)
                {
                    byteList.AddRange((fct.Value + Fee).ToFactoshi().EncodeVarInt_F());
                }
                else
                {
                    byteList.AddRange(fct.Value.ToFactoshi().EncodeVarInt_F());
                }
                byteList.AddRange(fct.Key.Public.FactomBase58ToBytes());
            }

            // Factoid Outputs
            // varInt_F (Output X) This is how much the Output X Factoshi balance will be increased by.
            // 32 bytes (Output X) This is an RCD hash which will have its balance increased.
            foreach (var fct in FCT_Output)
            {
                byteList.AddRange(fct.Value.ToFactoshi().EncodeVarInt_F());
                byteList.AddRange(fct.Key.Public.FactomBase58ToBytes());
            }


            // Entry Credit Purchase
            // varInt_F (Purchase X) This many Factoshis worth of ECs will be credited to the Entry Credit public key X.
            // 32 bytes EC Pubkey (Purchase X) This is Entry Credit public key that will have its balance increased.
            foreach (var ec in EC_Output)
            {
                byteList.AddRange(ec.Value.ToFactoshi().EncodeVarInt_F());
                byteList.AddRange(ec.Key.Public.FactomBase58ToBytes());
            }

            var marshalBinary = byteList.ToArray();

            TXID = SHA256.Create().ComputeHash(marshalBinary);

            return(marshalBinary);
        }
示例#2
0
        public String GetHexString()
        {
            if (ChainID == null)
            {
                new Exception("Chain ID not set");
            }

            Entry = new EntryData(ChainID, DataEntry, ExtIDs);

            var byteList = new List <byte>();

            //1 byte version
            byteList.Add(0);

            // 6 byte milliTimestamp (truncated unix time)
            byteList.AddRange(FactomUtils.MilliTime());
            //32 byte Entry Hash
            byteList.AddRange(Entry.Hash);

            // 1 byte number of Entry Credits to pay
            byteList.Add(Entry.EntryCost);

            //Sign
            var signature = EcAddress.SignFunction(byteList.ToArray());

            //Add in the EC Public key (strip off header and checksum)
            byteList.AddRange(EcAddress.Public.FactomBase58ToBytes());

            //Add signature
            byteList.AddRange(signature);

            return(byteList.ToArray().ToHexString());
        }
        public string GetHexString()
        {
            if (ExtIDs == null)
            {
                ExtIDs = FactomUtils.MakeExtIDs();
            }

            var chainHash = new List <byte>();

            foreach (var extId in ExtIDs)
            {
                var h = SHA256.Create().ComputeHash(extId);
                chainHash.AddRange(h);
            }

            byte[] ChainId;
            if (ChainIdString != null)
            {
                ChainId = ChainIdString.DecodeHexIntoBytes();
            }
            else
            {
                ChainId = SHA256.Create().ComputeHash(chainHash.ToArray());
            }

            Entry = new EntryData(ChainId, FirstEntry, ExtIDs);

            var byteList = new List <byte>();

            //1 byte version
            byteList.Add(0);

            // 6 byte milliTimestamp (truncated unix time)
            byteList.AddRange(FactomUtils.MilliTime());

            // 32 Byte ChainID Hash
            //byte[] chainIDHash = Encoding.ASCII.GetBytes(c.ChainId);
            var chainIDHash = Entry.ChainId;

            chainIDHash = SHA256.Create().ComputeHash(chainIDHash);
            chainIDHash = SHA256.Create().ComputeHash(chainIDHash);
            byteList.AddRange(chainIDHash);

            // 32 byte Weld; sha256(sha256(EntryHash + ChainID))
            var cid  = Entry.ChainId;
            var s    = Entry.Hash;
            var weld = new byte[cid.Length + s.Length];

            s.CopyTo(weld, 0);
            cid.CopyTo(weld, s.Length);
            weld = SHA256.Create().ComputeHash(weld);
            weld = SHA256.Create().ComputeHash(weld);
            byteList.AddRange(weld);

            // 32 byte Entry Hash of the First Entry
            byteList.AddRange(Entry.Hash);

            // 1 byte number of Entry Credits to pay
            byteList.Add((byte)(Entry.EntryCost + 10));

            //Sign
            var signature = ECaddress.SignFunction(byteList.ToArray());

            //Add in the EC Public key (strip off header and checksum)
            // byteList.AddRange(ECPublicBytes.ToArray());
            byteList.AddRange(ECaddress.Public.FactomBase58ToBytes().ToArray());

            //Add signature
            byteList.AddRange(signature);

            return(byteList.ToArray().ToHexString());
        }