Exemplo n.º 1
0
        /// <summary>
        /// Allocate an array. Intended for testing purposes only.
        /// </summary>
        internal static ProduceCoinRequest From(
            RequestId requestId,
            ClientId clientId,
            Outpoint outpoint,
            OutpointFlags flags,
            BlockAlias context,
            ulong satoshis,
            uint nLockTime,
            Span <byte> script,
            BlockHandleMask mask)
        {
            var request = new ProduceCoinRequest
            {
                _buffer = new Span <byte>(new byte[Header.SizeInBytes + script.Length])
            };

            request.MessageHeader.MessageSizeInBytes = Header.SizeInBytes + script.Length;
            request.MessageHeader.RequestId          = requestId;
            request.MessageHeader.ClientId           = clientId;
            request.MessageHeader.MessageKind        = MessageKind.ProduceCoin;

            request.AsHeader.Outpoint  = outpoint;
            request.AsHeader.Flags     = flags;
            request.AsHeader.Context   = context.ConvertToBlockHandle(mask);
            request.AsHeader.Satoshis  = satoshis;
            request.AsHeader.NLockTime = nLockTime;

            script.CopyTo(request._buffer.Slice(Header.SizeInBytes));

            return(request);
        }
Exemplo n.º 2
0
        public GetCoinResponse(
            RequestId requestId,
            ClientId clientId,
            GetCoinStatus status,
            ref Outpoint outpoint,
            OutpointFlags flags,
            BlockAlias context,
            BlockAlias production,
            BlockAlias consumption,
            ulong satoshis,
            uint nLockTime,
            Span <byte> script,
            BlockHandleMask mask,
            SpanPool <byte> pool)
        {
            var messageSizeInBytes = Header.SizeInBytes + script.Length;

            _buffer = pool.GetSpan(messageSizeInBytes);

            AsHeader.ResponseHeader.MessageSizeInBytes = messageSizeInBytes;
            AsHeader.ResponseHeader.RequestId          = requestId;
            AsHeader.ResponseHeader.ClientId           = clientId;
            AsHeader.ResponseHeader.MessageKind        = MessageKind.GetCoinResponse;

            AsHeader.Status      = status;
            AsHeader.Outpoint    = outpoint;
            AsHeader.Flags       = flags;
            AsHeader.Context     = context.ConvertToBlockHandle(mask);
            AsHeader.Production  = production.ConvertToBlockHandle(mask);
            AsHeader.Consumption = consumption.ConvertToBlockHandle(mask);
            AsHeader.Satoshis    = satoshis;
            AsHeader.NLockTime   = nLockTime;

            script.CopyTo(_buffer.Slice(Header.SizeInBytes));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Allocate an array. Intended for testing purposes only.
 /// </summary>
 internal static ConsumeCoinRequest From(RequestId requestId,
                                         ref Outpoint outpoint,
                                         BlockAlias context,
                                         BlockHandleMask mask)
 {
     return(new ConsumeCoinRequest(requestId, ref outpoint,
                                   context.ConvertToBlockHandle(mask), new SpanPool <byte>(Header.SizeInBytes)));
 }
Exemplo n.º 4
0
        public GetBlockHandleResponse(
            ref MessageHeader requestHeader, BlockHandleMask mask, BlockAlias alias, SpanPool <byte> pool)
        {
            _buffer = pool.GetSpan(Header.SizeInBytes);

            AsHeader.ResponseHeader = requestHeader;

            AsHeader.ResponseHeader.MessageKind        = MessageKind.BlockHandleResponse;
            AsHeader.ResponseHeader.MessageSizeInBytes = Header.SizeInBytes;

            AsHeader.Status = GetBlockHandleStatus.Success;
            AsHeader.Handle = alias.ConvertToBlockHandle(mask);
        }
Exemplo n.º 5
0
        public OpenBlockResponse(
            ref MessageHeader requestHeader, BlockHandleMask mask, BlockAlias alias, UncommittedBlockId uncommittedBlockId, SpanPool <byte> pool)
        {
            _buffer = pool.GetSpan(Header.SizeInBytes);

            AsHeader.ResponseHeader = requestHeader;

            AsHeader.ResponseHeader.MessageKind        = MessageKind.OpenBlockResponse;
            AsHeader.ResponseHeader.MessageSizeInBytes = Header.SizeInBytes;

            AsHeader.Status             = OpenBlockStatus.Success;
            AsHeader.Handle             = alias.ConvertToBlockHandle(mask);
            AsHeader.UncommittedBlockId = uncommittedBlockId;
        }
Exemplo n.º 6
0
        /// <summary> Client-side perspective. </summary>
        public GetCoinRequest(
            RequestId requestId,
            ref Outpoint outpoint,
            BlockHandle context,
            SpanPool <byte> pool)
        {
            _buffer = pool.GetSpan(Header.SizeInBytes);
            _mask   = default;

            AsHeader.RequestHeader.MessageSizeInBytes = Header.SizeInBytes;
            AsHeader.RequestHeader.RequestId          = requestId;
            AsHeader.RequestHeader.MessageKind        = MessageKind.GetCoin;

            Outpoint      = outpoint;
            HandleContext = context;
        }
Exemplo n.º 7
0
        public void Setup()
        {
            var dispatchInbox = new BoundedInbox();
            var chainInbox    = new BoundedInbox();
            var coinInboxes   = new BoundedInbox[ShardCount];

            for (var i = 0; i < coinInboxes.Length; i++)
            {
                coinInboxes[i] = new BoundedInbox();
            }

            _dispatcher = new DispatchController(
                dispatchInbox,
                chainInbox,
                coinInboxes,
                new IdentityHash());

            // Configure the wake-up callbacks to do nothing.
            _dispatcher.OnBlockMessageDispatched = () => { };
            for (var i = 0; i < _dispatcher.OnCoinMessageDispatched.Length; i++)
            {
                _dispatcher.OnCoinMessageDispatched[i] = () => { }
            }
            ;

            _store = new VolatileChainStore();

            _chainController = new ChainController(
                _store,
                chainInbox,
                dispatchInbox,
                lineage => { });

            var c1 = ClientId.Next();

            _clientConn = new ConnectionController(dispatchInbox, _socket, c1);
            _handleMask = c1.Mask;

            _dispatcher.AddConnection(_clientConn);
            _dispatcher.OnConnectionAccepted = _ => { };
            _dispatcher.HandleNewConnection();

            _c0 = new ClientId(0);
        }
Exemplo n.º 8
0
        /// <summary> Coin removal. Client-side perspective. </summary>
        public RemoveCoinRequest(
            Span <byte> buffer,
            RequestId requestId,
            ref Outpoint outpoint,
            BlockHandle context,
            bool removeProduction,
            bool removeConsumption)
        {
            _buffer = buffer;
            _mask   = default;

            AsHeader.RequestHeader.MessageSizeInBytes = Header.SizeInBytes;
            AsHeader.RequestHeader.RequestId          = requestId;
            AsHeader.RequestHeader.MessageKind        = MessageKind.RemoveCoin;

            Outpoint          = outpoint;
            HandleContext     = context;
            RemoveProduction  = removeProduction;
            RemoveConsumption = removeConsumption;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Allocate an array. Intended for testing purposes only.
        /// </summary>
        internal static GetCoinRequest From(
            RequestId requestId,
            ClientId clientId,
            Outpoint outpoint,
            BlockAlias context,
            BlockHandleMask mask)
        {
            var request = new GetCoinRequest {
                _buffer = new Span <byte>(new byte[Header.SizeInBytes])
            };

            request.MessageHeader.MessageSizeInBytes = Header.SizeInBytes;
            request.MessageHeader.RequestId          = requestId;
            request.MessageHeader.ClientId           = clientId;
            request.MessageHeader.MessageKind        = MessageKind.GetCoin;

            request.AsHeader.Outpoint = outpoint;
            request.AsHeader.Context  = context.ConvertToBlockHandle(mask);

            return(request);
        }
Exemplo n.º 10
0
        public GetBlockInfoResponse(
            ref MessageHeader requestHeader,
            UncommittedBlockId uncommittedBlockId,
            BlockAlias alias,
            BlockAlias parent,
            int blockHeight,
            BlockHandleMask mask,
            SpanPool <byte> pool)
        {
            _buffer = pool.GetSpan(Header.SizeInBytes);

            AsHeader.ResponseHeader                    = requestHeader;
            AsHeader.ResponseHeader.MessageKind        = MessageKind.BlockInfoResponse;
            AsHeader.ResponseHeader.MessageSizeInBytes = Header.SizeInBytes;

            AsHeader.UncommittedBlockId = uncommittedBlockId;
            AsHeader.Handle             = alias.ConvertToBlockHandle(mask);
            AsHeader.Parent             = parent.ConvertToBlockHandle(mask);
            AsHeader.BlockHeight        = blockHeight;
            AsHeader.IsCommitted        = false;
        }
Exemplo n.º 11
0
        /// <summary> Coin production. Client-side perspective. </summary>
        public ProduceCoinRequest(
            RequestId requestId,
            ref Outpoint outpoint,
            OutpointFlags flags,
            BlockHandle context,
            ulong satoshis,
            uint nLockTime,
            int scriptSizeInBytes,
            SpanPool <byte> pool)
        {
            _buffer = pool.GetSpan(Header.SizeInBytes + scriptSizeInBytes);
            _mask   = default;

            AsHeader.RequestHeader.MessageSizeInBytes = Header.SizeInBytes + scriptSizeInBytes;
            AsHeader.RequestHeader.RequestId          = requestId;
            AsHeader.RequestHeader.MessageKind        = MessageKind.ProduceCoin;

            Outpoint      = outpoint;
            HandleContext = context;
            Flags         = flags;
            Satoshis      = satoshis;
            NLockTime     = nLockTime;
        }
Exemplo n.º 12
0
 public ProduceCoinRequest(Span <byte> buffer, BlockHandleMask mask)
 {
     _buffer = buffer;
     _mask   = mask;
 }
Exemplo n.º 13
0
 public OpenBlockRequest(Span <byte> buffer, BlockHandleMask mask)
 {
     _buffer = buffer;
     _mask   = mask;
 }
Exemplo n.º 14
0
 public GetBlockInfoRequest(Span <byte> buffer, BlockHandleMask mask)
 {
     _buffer = buffer;
     _mask   = mask;
 }