本文整理汇总了C#中BitcoinStream.ReadWriteAsVarInt方法的典型用法代码示例。如果您正苦于以下问题:C# BitcoinStream.ReadWriteAsVarInt方法的具体用法?C# BitcoinStream.ReadWriteAsVarInt怎么用?C# BitcoinStream.ReadWriteAsVarInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitcoinStream
的用法示例。
在下文中一共展示了BitcoinStream.ReadWriteAsVarInt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadData
private bool ReadData(byte[] data)
{
try
{
BitcoinStream stream = new BitcoinStream(data);
ushort marker = 0;
stream.ReadWrite(ref marker);
if(marker != Tag)
return false;
stream.ReadWrite(ref _Version);
if(_Version != 1)
return false;
ulong quantityCount = 0;
stream.ReadWriteAsVarInt(ref quantityCount);
Quantities = new ulong[quantityCount];
for(ulong i = 0 ; i < quantityCount ; i++)
{
Quantities[i] = ReadLEB128(stream);
if(Quantities[i] > MAX_QUANTITY)
return false;
}
stream.ReadWriteAsVarString(ref _Metadata);
if(stream.Inner.Position != data.Length)
return false;
return true;
}
catch(Exception)
{
return false;
}
}
示例2: ReadScript
private bool ReadScript(Script script)
{
try
{
var data = TxNullDataTemplate.Instance.ExtractScriptPubKeyParameters(script);
if(data == null)
return false;
BitcoinStream stream = new BitcoinStream(data);
ushort marker = 0;
stream.ReadWrite(ref marker);
if(marker != Tag)
return false;
stream.ReadWrite(ref _Version);
if(_Version != 1)
return false;
ulong quantityCount = 0;
stream.ReadWriteAsVarInt(ref quantityCount);
Quantities = new ulong[quantityCount];
for(ulong i = 0 ; i < quantityCount ; i++)
{
Quantities[i] = ReadLEB128(stream);
if(Quantities[i] > MAX_QUANTITY)
return false;
}
stream.ReadWriteAsVarString(ref _Metadata);
return true;
}
catch(Exception)
{
return false;
}
}
示例3: ReadWriteCore
public override void ReadWriteCore(BitcoinStream stream)
{
stream.ReadWrite(ref _BlockId);
ulong indexes_size = (ulong)_Indices.Count;
stream.ReadWriteAsVarInt(ref indexes_size);
if(!stream.Serializing)
{
ulong i = 0;
ulong indicesCount = 0;
while((ulong)_Indices.Count < indexes_size)
{
indicesCount = Math.Min(1000UL + (ulong)indicesCount, (ulong)indexes_size);
for(; i < indicesCount; i++)
{
ulong index = 0;
stream.ReadWriteAsVarInt(ref index);
if(index > Int32.MaxValue)
throw new FormatException("indexes overflowed 31-bits");
_Indices.Add((int)index);
}
}
int offset = 0;
for(var ii = 0; ii < _Indices.Count; ii++)
{
if((ulong)(_Indices[ii]) + (ulong)(offset) > Int32.MaxValue)
throw new FormatException("indexes overflowed 31-bits");
_Indices[ii] = _Indices[ii] + offset;
offset = _Indices[ii] + 1;
}
}
else
{
for(var i = 0; i < _Indices.Count; i++)
{
int index = _Indices[i] - (i == 0 ? 0 : (_Indices[i - 1] + 1));
stream.ReadWrite(ref index);
}
}
}
示例4: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
stream.ReadWriteAsVarInt(ref _Index);
if(stream.Serializing)
{
byte[] assetId = Asset.Id.ToBytes();
stream.ReadWrite(ref assetId);
long quantity = Asset.Quantity;
stream.ReadWrite(ref quantity);
}
else
{
byte[] assetId = new byte[20];
stream.ReadWrite(ref assetId);
long quantity = 0;
stream.ReadWrite(ref quantity);
Asset = new AssetMoney(new AssetId(assetId), quantity);
}
}
示例5: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
if(stream.Serializing)
{
uint nMaskSize = 0, nMaskCode = 0;
CalcMaskSize(ref nMaskSize, ref nMaskCode);
bool fFirst = vout.Count > 0 && !vout[0].IsNull;
bool fSecond = vout.Count > 1 && !vout[1].IsNull;
uint nCode = unchecked((uint)(8 * (nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0)));
// version
stream.ReadWriteAsVarInt(ref nVersion);
// size of header code
stream.ReadWriteAsVarInt(ref nCode);
// spentness bitmask
for(uint b = 0 ; b < nMaskSize ; b++)
{
byte chAvail = 0;
for(uint i = 0 ; i < 8 && 2 + b * 8 + i < vout.Count ; i++)
if(!vout[2 + (int)b * 8 + (int)i].IsNull)
chAvail |= (byte)(1 << (int)i);
stream.ReadWrite(ref chAvail);
}
// txouts themself
for(uint i = 0 ; i < vout.Count ; i++)
{
if(!vout[(int)i].IsNull)
{
var compressedTx = new TxOutCompressor(vout[(int)i]);
stream.ReadWrite(ref compressedTx);
}
}
// coinbase height
stream.ReadWriteAsVarInt(ref nHeight);
}
else
{
uint nCode = 0;
// version
stream.ReadWriteAsVarInt(ref nVersion);
//// header code
stream.ReadWriteAsVarInt(ref nCode);
fCoinBase = (nCode & 1) != 0;
List<bool> vAvail = new List<bool>() { false, false };
vAvail[0] = (nCode & 2) != 0;
vAvail[1] = (nCode & 4) != 0;
uint nMaskCode = unchecked((uint)((nCode / 8) + ((nCode & 6) != 0 ? 0 : 1)));
//// spentness bitmask
while(nMaskCode > 0)
{
byte chAvail = 0;
stream.ReadWrite(ref chAvail);
for(uint p = 0 ; p < 8 ; p++)
{
bool f = (chAvail & (1 << (int)p)) != 0;
vAvail.Add(f);
}
if(chAvail != 0)
nMaskCode--;
}
// txouts themself
vout = Enumerable.Range(0, vAvail.Count).Select(_ => new TxOut()).ToList();
for(uint i = 0 ; i < vAvail.Count ; i++)
{
if(vAvail[(int)i])
{
TxOutCompressor compressed = new TxOutCompressor();
stream.ReadWrite(ref compressed);
vout[(int)i] = compressed.TxOut;
}
}
//// coinbase height
stream.ReadWriteAsVarInt(ref nHeight);
Cleanup();
UpdateValue();
}
}
示例6: ToBytes
public byte[] ToBytes()
{
MemoryStream ms = new MemoryStream();
BitcoinStream stream = new BitcoinStream(ms, true);
stream.ReadWrite(Tag);
stream.ReadWrite(ref _Version);
var quantityCount = (uint)this.Quantities.Length;
stream.ReadWriteAsVarInt(ref quantityCount);
for(int i = 0 ; i < quantityCount ; i++)
{
if(Quantities[i] > MAX_QUANTITY)
throw new ArgumentOutOfRangeException("Quantity should not exceed " + Quantities[i]);
WriteLEB128(Quantities[i], stream);
}
stream.ReadWriteAsVarString(ref _Metadata);
return ms.ToArray();
}
示例7: GetScript
public Script GetScript()
{
MemoryStream ms = new MemoryStream();
BitcoinStream stream = new BitcoinStream(ms, true);
stream.ReadWrite(Tag);
stream.ReadWrite(ref _Version);
var quantityCount = (uint)this.Quantities.Length;
stream.ReadWriteAsVarInt(ref quantityCount);
for(int i = 0 ; i < quantityCount ; i++)
{
if(Quantities[i] > MAX_QUANTITY)
throw new ArgumentOutOfRangeException("Quantity should not exceed " + Quantities[i]);
WriteLEB128(Quantities[i], stream);
}
stream.ReadWriteAsVarString(ref _Metadata);
return TxNullDataTemplate.Instance.GenerateScriptPubKey(ms.ToArray());
}
示例8: ReadWriteCore
public override void ReadWriteCore(BitcoinStream stream)
{
stream.ReadWrite(ref _Header);
stream.ReadWrite(ref _Nonce);
var shorttxids_size = (uint)_ShortIds.Count;
stream.ReadWriteAsVarInt(ref shorttxids_size);
if(!stream.Serializing)
{
ulong i = 0;
ulong shottxidsCount = 0;
while(_ShortIds.Count < shorttxids_size)
{
shottxidsCount = Math.Min(1000UL + (ulong)shottxidsCount, (ulong)shorttxids_size);
for(; i < shottxidsCount; i++)
{
uint lsb = 0;
ushort msb = 0;
stream.ReadWrite(ref lsb);
stream.ReadWrite(ref msb);
_ShortIds.Add(((ulong)(msb) << 32) | (ulong)(lsb));
}
}
}
else
{
for(var i = 0; i < _ShortIds.Count; i++)
{
uint lsb = (uint)(_ShortIds[i] & 0xffffffff);
ushort msb = (ushort)((_ShortIds[i] >> 32) & 0xffff);
stream.ReadWrite(ref lsb);
stream.ReadWrite(ref msb);
}
}
ulong txn_size = (ulong)PrefilledTransactions.Count;
stream.ReadWriteAsVarInt(ref txn_size);
if(!stream.Serializing)
{
ulong i = 0;
ulong indicesCount = 0;
while((ulong)PrefilledTransactions.Count < txn_size)
{
indicesCount = Math.Min(1000UL + (ulong)indicesCount, (ulong)txn_size);
for(; i < indicesCount; i++)
{
ulong index = 0;
stream.ReadWriteAsVarInt(ref index);
if(index > Int32.MaxValue)
throw new FormatException("indexes overflowed 32-bits");
Transaction tx = null;
stream.ReadWrite(ref tx);
PrefilledTransactions.Add(new PrefilledTransaction()
{
Index = (int)index,
Transaction = tx
});
}
}
int offset = 0;
for(var ii = 0; ii < PrefilledTransactions.Count; ii++)
{
if((ulong)(PrefilledTransactions[ii].Index) + (ulong)(offset) > Int32.MaxValue)
throw new FormatException("indexes overflowed 31-bits");
PrefilledTransactions[ii].Index = PrefilledTransactions[ii].Index + offset;
offset = PrefilledTransactions[ii].Index + 1;
}
}
else
{
for(var i = 0; i < PrefilledTransactions.Count; i++)
{
uint index = checked((uint)(PrefilledTransactions[i].Index - (i == 0 ? 0 : (PrefilledTransactions[i - 1].Index + 1))));
stream.ReadWriteAsVarInt(ref index);
Transaction tx = PrefilledTransactions[i].Transaction;
stream.ReadWrite(ref tx);
}
}
if(!stream.Serializing)
UpdateShortTxIDSelector();
}