private string GetRoundInfoToString(UInt64Value roundNumber) { try { var result = ""; foreach (var bpInfo in this[roundNumber].BlockProducers) { result += bpInfo.Key + ":\n"; result += "IsEBP:\t\t" + bpInfo.Value.IsEBP + "\n"; result += "Order:\t\t" + bpInfo.Value.Order + "\n"; result += "Time Slot:\t" + bpInfo.Value.TimeSlot.ToDateTime().ToLocalTime().ToString("u") + "\n"; result += "Signature:\t" + bpInfo.Value.Signature?.Value.ToByteArray().ToHex().RemoveHexPrefix() + "\n"; result += "Out Value:\t" + bpInfo.Value.OutValue?.Value.ToByteArray().ToHex().RemoveHexPrefix() + "\n"; result += "In Value:\t" + bpInfo.Value.InValue?.Value.ToByteArray().ToHex().RemoveHexPrefix() + "\n"; } return(result + "\n"); } catch (Exception e) { _logger?.Error(e, $"Failed to get dpos info of round {roundNumber.Value}"); return(""); } }
public bool Transfer(Address from, Address to, UInt64Value qty) { Console.WriteLine("From: " + from.DumpHex()); Console.WriteLine("To: " + to.DumpHex()); // This is for testing batched transaction sequence TransactionStartTimes.SetValue(Api.GetTransaction().GetHash(), Now()); var fromBal = Balances.GetValue(from); Console.WriteLine("Old From Balance: " + fromBal); var toBal = Balances.GetValue(to); Console.WriteLine("Old To Balance: " + toBal); Console.WriteLine("Assertion: " + (fromBal >= qty.Value)); Api.Assert(fromBal >= qty.Value, $"Insufficient balance, {qty.Value} is required but there is only {fromBal}."); var newFromBal = fromBal - qty.Value; var newToBal = toBal + qty.Value; Console.WriteLine("New From Balance: " + newFromBal); Console.WriteLine("New To Balance: " + newToBal); Balances.SetValue(from, newFromBal); Balances.SetValue(to, newToBal); // This is for testing batched transaction sequence TransactionEndTimes.SetValue(Api.GetTransaction().GetHash(), Now()); return(true); }
public void WriteParentChainBlockInfo(ParentChainBlockInfo parentChainBlockInfo) { ulong parentChainHeight = parentChainBlockInfo.Height; var currentHeight = _currentParentChainHeight.GetValue(); var target = currentHeight != 0 ? currentHeight + 1: GlobalConfig.GenesisBlockHeight; Api.Assert(target == parentChainHeight, $"Parent chain block info at height {target} is needed, not {parentChainHeight}"); Console.WriteLine("ParentChainBlockInfo.Height is correct."); var key = new UInt64Value { Value = parentChainHeight }; Api.Assert(_parentChainBlockInfo.GetValue(key) == null, $"Already written parent chain block info at height {parentChainHeight}"); Console.WriteLine("Writing ParentChainBlockInfo.."); foreach (var _ in parentChainBlockInfo.IndexedBlockInfo) { BindParentChainHeight(_.Key, parentChainHeight); AddIndexedTxRootMerklePathInParentChain(_.Key, _.Value); } _parentChainBlockInfo.SetValueAsync(key, parentChainBlockInfo).Wait(); _currentParentChainHeight.SetValue(parentChainHeight); // only for debug Console.WriteLine($"WriteParentChainBlockInfo success at {parentChainHeight}"); }
private async Task SetDPoSInformationOfNextRound(Round nextRoundInfo, StringValue nextExtraBlockProducer) { //Update Current Round Number. await UpdateCurrentRoundNumber(); var newRoundNumber = new UInt64Value { Value = CurrentRoundNumber }; //Update ExtraBlockProducer. await SetExtraBlockProducerOfSpecificRound(newRoundNumber, nextExtraBlockProducer); //Update RoundInfo. nextRoundInfo.BlockProducers.First(info => info.Key == nextExtraBlockProducer.Value).Value.IsEBP = true; //Update DPoSInfo. await SetDPoSInfoToMap(newRoundNumber, nextRoundInfo); //Update First Place. await SetFirstPlaceOfSpecificRound(newRoundNumber, new StringValue { Value = nextRoundInfo.BlockProducers.First().Key }); //Update Extra Block Time Slot. await SetExtraBlockMiningTimeSlotOfSpecificRound(GetTimestampWithOffset( nextRoundInfo.BlockProducers.Last().Value.TimeSlot, Interval)); ConsoleWriteLine(nameof(Update), $"Sync dpos info of round {CurrentRoundNumber} succeed."); }
public override UInt64Value Fibonacci(UInt64Value input) { var result = CalculateFibonacci(input.Value); return(new UInt64Value { Value = result }); }
public Round GetCurrentRoundInfo(UInt64Value currentRoundNumber = null) { if (currentRoundNumber == null) { currentRoundNumber = CurrentRoundNumber; } return(currentRoundNumber.Value != 0 ? this[currentRoundNumber] : null); }
// ReSharper disable once MemberCanBeMadeStatic.Local private UInt64Value RoundNumberMinusOne(UInt64Value currentCount) { var current = currentCount.Value; current--; return(new UInt64Value { Value = current }); }
private void AddIndexedTxRootMerklePathInParentChain(ulong height, MerklePath path) { var key = new UInt64Value { Value = height }; Api.Assert(_txRootMerklePathInParentChain.GetValue(key) == null, $"Merkle path already bound at height {height}."); // _txRootMerklePathInParentChain[key] = path; _txRootMerklePathInParentChain.SetValueAsync(key, path).Wait(); Console.WriteLine("Path: {0}", path.Path[0].DumpHex()); }
private async Task PublishInValue(UInt64Value roundNumber, StringValue accountAddress, Hash inValue) { var info = await GetBPInfoOfSpecificRound(accountAddress, roundNumber); info.InValue = inValue; var roundInfo = await _dPoSInfoMap.GetValueAsync(roundNumber); roundInfo.BlockProducers[accountAddress.Value] = info; await _dPoSInfoMap.SetValueAsync(roundNumber, roundInfo); }
private void BindParentChainHeight(ulong childHeight, ulong parentHeight) { var key = new UInt64Value { Value = childHeight }; Api.Assert(_childHeightToParentChainHeight.GetValue(key) == null, $"Already bound at height {childHeight} with parent chain"); // _childHeightToParentChainHeight[key] = new UInt64Value {Value = parentHeight}; _childHeightToParentChainHeight.SetValueAsync(key, new UInt64Value { Value = parentHeight }).Wait(); }
public bool VerifyTransaction(Hash tx, MerklePath path, ulong parentChainHeight) { var key = new UInt64Value { Value = parentChainHeight }; Api.Assert(_parentChainBlockInfo.GetValue(key) != null, $"Parent chain block at height {parentChainHeight} is not recorded."); var rootCalculated = path.ComputeRootWith(tx); var parentRoot = _parentChainBlockInfo.GetValue(key)?.Root?.SideChainTransactionsRoot; //Api.Assert((parentRoot??Hash.Zero).Equals(rootCalculated), "Transaction verification Failed"); return((parentRoot ?? Hash.Zero).Equals(rootCalculated)); }
public void NullableWrapper_Root_UInt64_WriteAsStrings(bool writeInt64sAsStrings, string expectedJson) { var v = new UInt64Value { Value = 2 }; var settings = new GrpcJsonSettings { WriteInt64sAsStrings = writeInt64sAsStrings }; var jsonSerializerOptions = CreateSerializerOptions(settings, TypeRegistry.Empty); var json = JsonSerializer.Serialize(v, jsonSerializerOptions); Assert.Equal(expectedJson, json); }
private async Task PublishOutValueAndSignature(UInt64Value roundNumber, StringValue accountAddress, Hash outValue, Hash signature) { var info = await GetBPInfoOfSpecificRound(accountAddress, roundNumber); info.OutValue = outValue; if (roundNumber.Value > 1) { info.Signature = signature; } var roundInfo = await _dPoSInfoMap.GetValueAsync(roundNumber); roundInfo.BlockProducers[accountAddress.Value] = info; await _dPoSInfoMap.SetValueAsync(roundNumber, roundInfo); }
/// <summary> /// Converts the serialized protobuf data to human friendly representation. /// </summary> /// <returns></returns> public byte[] ToFriendlyBytes() { switch (Type) { case Types.RetType.Bool: var boolval = new BoolValue(); ((IMessage)boolval).MergeFrom(this.Data); return(BitConverter.GetBytes(boolval.Value)); case Types.RetType.Int32: var sint32Val = new SInt32Value(); ((IMessage)sint32Val).MergeFrom(this.Data); return(GetFriendlyBytes(sint32Val.Value)); case Types.RetType.Uint32: var uint32Val = new UInt32Value(); ((IMessage)uint32Val).MergeFrom(this.Data); return(GetFriendlyBytes(uint32Val.Value)); case Types.RetType.Int64: var sint64Val = new SInt64Value(); ((IMessage)sint64Val).MergeFrom(this.Data); return(GetFriendlyBytes(sint64Val.Value)); case Types.RetType.Uint64: var uint64Val = new UInt64Value(); ((IMessage)uint64Val).MergeFrom(this.Data); return(GetFriendlyBytes(uint64Val.Value)); case Types.RetType.String: var stringVal = new StringValue(); ((IMessage)stringVal).MergeFrom(this.Data); return(GetFriendlyBytes(stringVal.Value)); case Types.RetType.Bytes: var bytesVal = new BytesValue(); ((IMessage)bytesVal).MergeFrom(this.Data); return(GetFriendlyBytes(bytesVal.Value.ToByteArray())); case Types.RetType.PbMessage: case Types.RetType.UserType: // Both are treated as bytes return(GetFriendlyBytes(Data.ToByteArray())); } return(new byte[0]); }
private Round this[UInt64Value roundNumber] { get { try { var bytes = GetBytes <Round>(Hash.FromMessage(roundNumber), GlobalConfig.AElfDPoSInformationString); var round = Round.Parser.ParseFrom(bytes); return(round); } catch (Exception e) { _logger.Error(e, $"Failed to get Round information of provided round number. - {roundNumber.Value}\n"); return(default(Round)); } } }
public void CanGetMarshallerForWellKnownType() { var marshaller = _sut.GetMarshaller <UInt64Value>(); var encodedValue = new UInt64Value { Value = ulong.MaxValue }; UInt64Value decodedValue; using (var stream = new MemoryStream()) { marshaller.Encode(encodedValue, stream); stream.Seek(0, SeekOrigin.Begin); decodedValue = marshaller.Decode(stream); } marshaller.MessageId.ShouldBe("google.protobuf.UInt64Value"); decodedValue.ShouldBe(encodedValue); }
public bool Initialize(Address account, UInt64Value qty) { Console.WriteLine($"Initialize {account.DumpHex()} to {qty.Value}"); Balances.SetValue(account, qty.Value); return(true); }
public void OpenXmlSimpleTypeConverterTest() { // 1. Base64BinaryValue Base64BinaryValue base64 = new Base64BinaryValue(); base64 = "AA3322"; Assert.True(base64 == "AA3322"); Assert.Equal("AA3322", base64.Value); base64 = Base64BinaryValue.FromString("1234"); Assert.Equal("1234", base64.ToString()); Assert.Equal("1234", Base64BinaryValue.ToString(base64)); // 2. BooleanValue BooleanValue booleanValue = new BooleanValue(); booleanValue = true; Assert.True(booleanValue); Assert.True(booleanValue.Value); booleanValue = BooleanValue.FromBoolean(false); Assert.False(booleanValue); Assert.False(BooleanValue.ToBoolean(booleanValue)); // 3. ByteValue ByteValue byteValue = new ByteValue(); byte bt = 1; byteValue = bt; Assert.True(bt == byteValue); Assert.Equal(bt, byteValue.Value); bt = 2; byteValue = ByteValue.FromByte(bt); Assert.Equal(bt, ByteValue.ToByte(byteValue)); // 4. DateTimeValue DateTimeValue dtValue = new DateTimeValue(); DateTime dt = DateTime.Now; dtValue = dt; Assert.True(dt == dtValue); dt = DateTime.Now.AddDays(1); dtValue = DateTimeValue.FromDateTime(dt); Assert.Equal(dt, dtValue.Value); Assert.Equal(dt, DateTimeValue.ToDateTime(dt)); // 5. DecimalValue DecimalValue decimalValue = new DecimalValue(); decimal dcm = 10; decimalValue = dcm; Assert.True(dcm == decimalValue); decimalValue = DecimalValue.FromDecimal(20); Assert.Equal(20, decimalValue.Value); Assert.Equal(20, DecimalValue.ToDecimal(decimalValue)); // 6. DoubleValue DoubleValue doubleValue = new DoubleValue(); double dbl = 1.1; doubleValue = dbl; Assert.True(dbl == doubleValue); doubleValue = DoubleValue.FromDouble(2.2); Assert.Equal(2.2, doubleValue.Value); Assert.Equal(2.2, DoubleValue.ToDouble(doubleValue)); // 7. HexBinaryValue HexBinaryValue hexBinaryValue = new HexBinaryValue(); string hex = "0X99CCFF"; hexBinaryValue = hex; Assert.True(hex == hexBinaryValue); hex = "111111"; hexBinaryValue = HexBinaryValue.FromString(hex); Assert.Equal(hex, hexBinaryValue.Value); Assert.Equal(hex, HexBinaryValue.ToString(hexBinaryValue)); // 8. Int16 Int16Value int16Value = new Int16Value(); short int16 = 16; int16Value = int16; Assert.True(int16 == int16Value); int16 = 17; int16Value = Int16Value.FromInt16(int16); Assert.Equal(int16, int16Value.Value); Assert.Equal(int16, Int16Value.ToInt16(int16Value)); // 9. Int32 Int32Value int32Value = new Int32Value(); int int32 = 32; int32Value = int32; Assert.True(int32 == int32Value); int32 = 33; int32Value = Int32Value.FromInt32(int32); Assert.Equal(int32, int32Value.Value); Assert.Equal(int32, Int32Value.ToInt32(int32Value)); // 10. Int64 Int64Value int64Value = new Int64Value(); long int64 = 64; int64Value = int64; Assert.True(int64 == int64Value); int64 = 17; int64Value = Int64Value.FromInt64(int64); Assert.Equal(int64, int64Value.Value); Assert.Equal(int64, Int64Value.ToInt64(int64Value)); // 11. IntegerValue IntegerValue integerValue = new IntegerValue(); int integer = 64; integerValue = integer; Assert.True(integer == integerValue); integer = 17; integerValue = IntegerValue.FromInt64(integer); Assert.Equal(integer, integerValue.Value); Assert.Equal(integer, IntegerValue.ToInt64(integerValue)); // 12. OnOffValue OnOffValue onOffValue = new OnOffValue(); onOffValue = true; Assert.True(onOffValue); onOffValue = OnOffValue.FromBoolean(false); Assert.False(onOffValue.Value); Assert.False(OnOffValue.ToBoolean(onOffValue)); // 13. SByteValue SByteValue sbyteValue = new SByteValue(); sbyte sbt = sbyte.MaxValue; sbyteValue = sbt; Assert.True(sbt == sbyteValue); sbt = sbyte.MinValue; sbyteValue = SByteValue.FromSByte(sbt); Assert.Equal(sbt, sbyteValue.Value); Assert.Equal(sbt, SByteValue.ToSByte(sbt)); // 14. SingleValue SingleValue singleValue = new SingleValue(); float single = float.MaxValue; singleValue = single; Assert.True(single == singleValue); single = float.NaN; singleValue = SingleValue.FromSingle(single); Assert.Equal(single, singleValue.Value); Assert.Equal(single, SingleValue.ToSingle(singleValue)); // 15. StringValue StringValue stringValue = new StringValue(); string str = "Ethan"; stringValue = str; Assert.True(str == stringValue); str = "Yin"; stringValue = StringValue.FromString(str); Assert.Equal(str, stringValue.Value); Assert.Equal(str, stringValue.ToString()); Assert.Equal(str, StringValue.ToString(stringValue)); // 16. TrueFalseBlankValue TrueFalseBlankValue tfbValue = new TrueFalseBlankValue(); tfbValue = true; Assert.True(tfbValue); tfbValue = TrueFalseBlankValue.FromBoolean(false); Assert.False(tfbValue.Value); Assert.False(TrueFalseBlankValue.ToBoolean(tfbValue)); // 17. TrueFalseValue TrueFalseValue tfValue = new TrueFalseValue(); tfValue = true; Assert.True(tfValue); tfValue = TrueFalseValue.FromBoolean(false); Assert.False(tfValue.Value); Assert.False(TrueFalseValue.ToBoolean(tfValue)); // 18. UInt16Value UInt16Value uint16Value = new UInt16Value(); ushort uint16 = ushort.MaxValue; uint16Value = uint16; Assert.True(uint16 == uint16Value); uint16 = ushort.MinValue; uint16Value = UInt16Value.FromUInt16(uint16); Assert.Equal(uint16, uint16Value.Value); Assert.Equal(uint16, UInt16Value.ToUInt16(uint16Value)); // 19. UInt32Value UInt32Value uint32Value = new UInt32Value(); uint uint32 = uint.MaxValue; uint32Value = uint32; Assert.True(uint32 == uint32Value); uint32 = uint.MinValue; uint32Value = UInt32Value.FromUInt32(uint32); Assert.Equal(uint32, uint32Value.Value); Assert.Equal(uint32, UInt32Value.ToUInt32(uint32Value)); // 20. UInt64Value UInt64Value uint64Value = new UInt64Value(); ulong uint64 = ulong.MaxValue; uint64Value = uint64; Assert.True(uint64 == uint64Value); uint64 = ulong.MinValue; uint64Value = UInt64Value.FromUInt64(uint64); Assert.Equal(uint64, uint64Value.Value); Assert.Equal(uint64, UInt64Value.ToUInt64(uint64Value)); }
private async Task SetFirstPlaceOfSpecificRound(UInt64Value roundNumber, AElfDPoSInformation info) { await _firstPlaceMap.SetValueAsync(roundNumber, new StringValue { Value = info.GetRoundInfo(roundNumber.Value).BlockProducers.First().Key }); }
private async Task SetFirstPlaceOfSpecificRound(UInt64Value roundNumber, StringValue accountAddress) { await _firstPlaceMap.SetValueAsync(roundNumber, accountAddress); }
private async Task SetDPoSInfoToMap(UInt64Value roundNumber, Round roundInfo) { await _dPoSInfoMap.SetValueAsync(roundNumber, roundInfo); await _roundHashMap.SetValueAsync(roundNumber, new Int64Value { Value = roundInfo.RoundId }); }
private async Task SetExtraBlockProducerOfSpecificRound(UInt64Value roundNumber, AElfDPoSInformation info) { await _eBPMap.SetValueAsync(roundNumber, info.GetExtraBlockProducerOfSpecificRound(roundNumber.Value)); }
public UInt64ValueTests() { SmallValue1 = new UInt64Value(10UL); SmallValue2 = new UInt64Value(10UL); LargeValue = new UInt64Value(20UL); }
public void OpenXmlSimpleTypeConverterTest() { // 1. Base64BinaryValue Base64BinaryValue base64 = new Base64BinaryValue(); base64 = "AA3322"; Assert.True("AA3322" == base64); Assert.Equal("AA3322", base64.Value); base64 = Base64BinaryValue.FromString("1234"); Assert.Equal("1234", base64.ToString()); Assert.Equal("1234", Base64BinaryValue.ToString(base64)); // 2. BooleanValue BooleanValue booleanValue = new BooleanValue(); booleanValue = true; Assert.True(booleanValue); Assert.True(booleanValue.Value); booleanValue = BooleanValue.FromBoolean(false); Assert.False(booleanValue); Assert.Equal(false, BooleanValue.ToBoolean(booleanValue)); // 3. ByteValue ByteValue byteValue = new ByteValue(); Byte bt = 1; byteValue = bt; Assert.True(bt == byteValue); Assert.Equal(bt, byteValue.Value); bt = 2; byteValue = ByteValue.FromByte(bt); Assert.Equal(bt, ByteValue.ToByte(byteValue)); // 4. DateTimeValue DateTimeValue dtValue = new DateTimeValue(); DateTime dt = DateTime.Now; dtValue = dt; Assert.True(dt == dtValue); dt = DateTime.Now.AddDays(1); dtValue = DateTimeValue.FromDateTime(dt); Assert.Equal(dt, dtValue.Value); Assert.Equal(dt, DateTimeValue.ToDateTime(dt)); // 5. DecimalValue DecimalValue decimalValue = new DecimalValue(); decimal dcm = 10; decimalValue = dcm; Assert.True(dcm == decimalValue); decimalValue = DecimalValue.FromDecimal(20); Assert.Equal(20, decimalValue.Value); Assert.Equal(20, DecimalValue.ToDecimal(decimalValue)); // 6. DoubleValue DoubleValue doubleValue = new DoubleValue(); double dbl = 1.1; doubleValue = dbl; Assert.True(dbl == doubleValue); doubleValue = DoubleValue.FromDouble(2.2); Assert.Equal(2.2, doubleValue.Value); Assert.Equal(2.2, DoubleValue.ToDouble(doubleValue)); // 7. HexBinaryValue HexBinaryValue hexBinaryValue = new HexBinaryValue(); string hex = "0X99CCFF"; hexBinaryValue = hex; Assert.True(hex == hexBinaryValue); hex = "111111"; hexBinaryValue = HexBinaryValue.FromString(hex); Assert.Equal(hex, hexBinaryValue.Value); Assert.Equal(hex, HexBinaryValue.ToString(hexBinaryValue)); // 8. Int16 Int16Value int16Value = new Int16Value(); Int16 int16 = 16; int16Value = int16; Assert.True(int16 == int16Value); int16 = 17; int16Value = Int16Value.FromInt16(int16); Assert.Equal(int16, int16Value.Value); Assert.Equal(int16, Int16Value.ToInt16(int16Value)); // 9. Int32 Int32Value int32Value = new Int32Value(); Int32 int32 = 32; int32Value = int32; Assert.True(int32 == int32Value); int32 = 33; int32Value = Int32Value.FromInt32(int32); Assert.Equal(int32, int32Value.Value); Assert.Equal(int32, Int32Value.ToInt32(int32Value)); // 10. Int64 Int64Value int64Value = new Int64Value(); Int64 int64 = 64; int64Value = int64; Assert.True(int64 == int64Value); int64 = 17; int64Value = Int64Value.FromInt64(int64); Assert.Equal(int64, int64Value.Value); Assert.Equal(int64, Int64Value.ToInt64(int64Value)); // 11. IntegerValue IntegerValue integerValue = new IntegerValue(); int integer = 64; integerValue = integer; Assert.True(integer == integerValue); integer = 17; integerValue = IntegerValue.FromInt64(integer); Assert.Equal(integer, integerValue.Value); Assert.Equal(integer, IntegerValue.ToInt64(integerValue)); // 12. OnOffValue OnOffValue onOffValue = new OnOffValue(); onOffValue = true; Assert.True(onOffValue); onOffValue = OnOffValue.FromBoolean(false); Assert.Equal(false, onOffValue.Value); Assert.Equal(false, OnOffValue.ToBoolean(onOffValue)); // 13. SByteValue SByteValue sbyteValue = new SByteValue(); SByte sbt = SByte.MaxValue; sbyteValue = sbt; Assert.True(sbt == sbyteValue); sbt = SByte.MinValue; sbyteValue = SByteValue.FromSByte(sbt); Assert.Equal(sbt, sbyteValue.Value); Assert.Equal(sbt, SByteValue.ToSByte(sbt)); // 14. SingleValue SingleValue singleValue = new SingleValue(); Single single = Single.MaxValue; singleValue = single; Assert.True(single == singleValue); single = Single.NaN; singleValue = SingleValue.FromSingle(single); Assert.Equal(single, singleValue.Value); Assert.Equal(single, SingleValue.ToSingle(singleValue)); // 15. StringValue StringValue stringValue = new StringValue(); String str = "Ethan"; stringValue = str; Assert.True(str == stringValue); str = "Yin"; stringValue = StringValue.FromString(str); Assert.Equal(str, stringValue.Value); Assert.Equal(str, stringValue.ToString()); Assert.Equal(str, StringValue.ToString(stringValue)); // 16. TrueFalseBlankValue TrueFalseBlankValue tfbValue = new TrueFalseBlankValue(); tfbValue = true; Assert.True(tfbValue); tfbValue = TrueFalseBlankValue.FromBoolean(false); Assert.Equal(false, tfbValue.Value); Assert.Equal(false, TrueFalseBlankValue.ToBoolean(tfbValue)); // 17. TrueFalseValue TrueFalseValue tfValue = new TrueFalseValue(); tfValue = true; Assert.True(tfValue); tfValue = TrueFalseValue.FromBoolean(false); Assert.Equal(false, tfValue.Value); Assert.Equal(false, TrueFalseValue.ToBoolean(tfValue)); // 18. UInt16Value UInt16Value uint16Value = new UInt16Value(); UInt16 uint16 = UInt16.MaxValue; uint16Value = uint16; Assert.True(uint16 == uint16Value); uint16 = UInt16.MinValue; uint16Value = UInt16Value.FromUInt16(uint16); Assert.Equal(uint16, uint16Value.Value); Assert.Equal(uint16, UInt16Value.ToUInt16(uint16Value)); // 19. UInt32Value UInt32Value uint32Value = new UInt32Value(); UInt32 uint32 = UInt32.MaxValue; uint32Value = uint32; Assert.True(uint32 == uint32Value); uint32 = UInt32.MinValue; uint32Value = UInt32Value.FromUInt32(uint32); Assert.Equal(uint32, uint32Value.Value); Assert.Equal(uint32, UInt32Value.ToUInt32(uint32Value)); // 20. UInt64Value UInt64Value uint64Value = new UInt64Value(); UInt64 uint64 = UInt64.MaxValue; uint64Value = uint64; Assert.True(uint64 == uint64Value); uint64 = UInt64.MinValue; uint64Value = UInt64Value.FromUInt64(uint64); Assert.Equal(uint64, uint64Value.Value); Assert.Equal(uint64, UInt64Value.ToUInt64(uint64Value)); }
/// <inheritdoc /> /// <summary> /// 1. Set block producers / miners; /// 2. Set current round number to 1; /// 3. Set mining interval; /// 4. Set first place of round 1 and 2 using AElfDPoSInformation; /// 5. Set DPoS information of first round to map; /// 6. Set EBP of round 1 and 2; /// 7. Set Extra Block mining time slot of current round (actually round 1). /// </summary> /// <param name="args"> /// 3 args: /// [0] Miners /// [1] AElfDPoSInformation /// [2] SInt32Value /// </param> /// <returns></returns> public async Task Initialize(List <byte[]> args) { if (args.Count != 4) { return; } var round1 = new UInt64Value { Value = 1 }; var round2 = new UInt64Value { Value = 2 }; Miners miners; AElfDPoSInformation dPoSInfo; SInt32Value miningInterval; try { miners = Miners.Parser.ParseFrom(args[0]); dPoSInfo = AElfDPoSInformation.Parser.ParseFrom(args[1]); miningInterval = SInt32Value.Parser.ParseFrom(args[2]); LogLevel = Int32Value.Parser.ParseFrom(args[3]).Value; } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to parse from byte array.", e); return; } // 1. Set block producers; try { await InitializeBlockProducer(miners); } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to set block producers.", e); } // 2. Set current round number to 1; try { await UpdateCurrentRoundNumber(1); } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to update current round number.", e); } // 3. Set mining interval; try { await SetMiningInterval(miningInterval); } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to set mining interval.", e); } // 4. Set first place of round 1 and 2 using DPoSInfo; try { await SetFirstPlaceOfSpecificRound(round1, dPoSInfo); await SetFirstPlaceOfSpecificRound(round2, dPoSInfo); } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to set first place.", e); } // 5. Set DPoS information of first round to map; try { await SetDPoSInfoToMap(round1, dPoSInfo.Rounds[0]); await SetDPoSInfoToMap(round2, dPoSInfo.Rounds[1]); } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to set DPoS information of first round to map.", e); } // 6. Set EBP of round 1 and 2; try { await SetExtraBlockProducerOfSpecificRound(round1, dPoSInfo); await SetExtraBlockProducerOfSpecificRound(round2, dPoSInfo); } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to set Extra Block Producer.", e); } // 7. Set Extra Block mining time slot of current round (actually round 1); try { await SetExtraBlockMiningTimeSlotOfSpecificRound(round1, dPoSInfo); } catch (Exception e) { ConsoleWriteLine(nameof(Initialize), "Failed to set Extra Block mining timeslot.", e); } }
private async Task <BlockProducer> GetBPInfoOfSpecificRound(StringValue accountAddress, UInt64Value roundNumber) { return((await _dPoSInfoMap.GetValueAsync(roundNumber)).BlockProducers[accountAddress.Value]); }
private async Task SetExtraBlockProducerOfSpecificRound(UInt64Value roundNumber, StringValue extraBlockProducer) { await _eBPMap.SetValueAsync(roundNumber, extraBlockProducer); }
private async Task SetExtraBlockMiningTimeSlotOfSpecificRound(UInt64Value roundNumber, AElfDPoSInformation info) { var lastMinerTimeSlot = info.GetLastBlockProducerTimeSlotOfSpecificRound(roundNumber.Value); var timeSlot = GetTimestampWithOffset(lastMinerTimeSlot, Interval); await _timeForProducingExtraBlockField.SetAsync(timeSlot); }