Skip to content

Commit a4e4c8d

Browse files
authored
Merge pull request #76 from nervosnetwork/release/v0.2.0
Release/v0.2.0
2 parents 9b11bcd + 1281722 commit a4e4c8d

28 files changed

+685
-19
lines changed

.ckb-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.41.0-rc1
1+
0.41.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img src="logo.png" width="250px">
2+
<img src="logo.png" width="256px">
33
</p>
44

55
![tippy](https://github.com/nervosnetwork/tippy/workflows/tippy/badge.svg)

logo.png

-25.6 KB
Loading

src/Ckb.Rpc/BaseClient.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,35 @@ public BaseClient(string url)
2727
Method = method,
2828
Params = methodParams
2929
};
30-
var serialized = JsonConvert.SerializeObject(request);
30+
var serialized = JsonConvert.SerializeObject(
31+
request,
32+
new JsonSerializerSettings
33+
{
34+
NullValueHandling = NullValueHandling.Ignore
35+
});
3136
var bytes = Encoding.UTF8.GetBytes(serialized);
3237
webRequest.ContentLength = bytes.Length;
33-
using Stream body = webRequest.GetRequestStream();
34-
body.Write(bytes, 0, bytes.Length);
3538

36-
using WebResponse webResponse = webRequest.GetResponse();
37-
using Stream responseStream = webResponse.GetResponseStream();
38-
using StreamReader responseReader = new StreamReader(responseStream);
39-
var response = JsonConvert.DeserializeObject<ResponseObject<T>>(responseReader.ReadToEnd());
40-
if (response != null)
41-
{
39+
try
40+
{
41+
using Stream body = webRequest.GetRequestStream();
42+
body.Write(bytes, 0, bytes.Length);
43+
44+
using WebResponse webResponse = webRequest.GetResponse();
45+
using Stream responseStream = webResponse.GetResponseStream();
46+
using StreamReader responseReader = new(responseStream);
47+
var response = JsonConvert.DeserializeObject<ResponseObject<T>>(responseReader.ReadToEnd());
48+
if (response == null)
49+
{
50+
throw new Exception("Parse JSON RPC response failed.");
51+
}
52+
4253
return response.Result;
4354
}
44-
return default;
55+
catch
56+
{
57+
return default;
58+
}
4559
}
4660
}
4761

src/Ckb.Rpc/Client.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,16 @@ public void ClearTxPool()
8888
{
8989
return Call<Types.RawTxPool>("get_raw_tx_pool", true);
9090
}
91+
92+
public Types.BlockTemplate? GetBlockTemplate()
93+
{
94+
return Call<Types.BlockTemplate>("get_block_template");
95+
}
96+
97+
public String? GenerateBlockWithTemplate(Types.BlockTemplate blockTemplate)
98+
{
99+
Types.BlockTemplate[] methodParams = { blockTemplate };
100+
return Call<String>("generate_block_with_template", methodParams);
101+
}
91102
}
92103
}

src/Ckb.Types/Types.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,97 @@ public class RawTxPool
351351
[JsonProperty(PropertyName = "proposed")]
352352
public Dictionary<string, TxVerbosity> Proposed { get; set; }
353353
}
354+
355+
public class CellbaseTemplate
356+
{
357+
[JsonProperty(PropertyName = "hash")]
358+
public string Hash { get; set; } = default;
359+
360+
[JsonProperty(PropertyName = "cycles")]
361+
public string Cycles { get; set; } = null;
362+
363+
[JsonProperty(PropertyName = "data")]
364+
public Transaction Data { get; set; }
365+
}
366+
367+
public class UncleTemplate
368+
{
369+
[JsonProperty(PropertyName = "hash")]
370+
public string Hash { get; set; } = default;
371+
372+
[JsonProperty(PropertyName = "required")]
373+
public bool Required { get; set; } = default;
374+
375+
[JsonProperty(PropertyName = "proposals")]
376+
public string[] Proposals { get; set; } = Array.Empty<string>();
377+
378+
[JsonProperty(PropertyName = "head")]
379+
public Header Header { get; set; } = default;
380+
}
381+
382+
public class TransactionTemplate
383+
{
384+
[JsonProperty(PropertyName = "hash")]
385+
public string Hash { get; set; } = default;
386+
387+
[JsonProperty(PropertyName = "required")]
388+
public bool Required { get; set; } = default;
389+
390+
[JsonProperty(PropertyName = "cycles")]
391+
public string Cycles { get; set; } = null;
392+
393+
[JsonProperty(PropertyName = "depends")]
394+
public string[] Depends { get; set; } = null;
395+
396+
[JsonProperty(PropertyName = "data")]
397+
public Transaction Data { get; set; }
398+
}
399+
400+
public class BlockTemplate
401+
{
402+
[JsonProperty(PropertyName = "version")]
403+
public string Version { get; set; } = default;
404+
405+
[JsonProperty(PropertyName = "compact_target")]
406+
public string CompactTarget { get; set; }
407+
408+
[JsonProperty(PropertyName = "current_time")]
409+
public string CurrentTime { get; set; }
410+
411+
[JsonProperty(PropertyName = "number")]
412+
public string Number { get; set; }
413+
414+
[JsonProperty(PropertyName = "epoch")]
415+
public string Epoch { get; set; }
416+
417+
[JsonProperty(PropertyName = "parent_hash")]
418+
public string ParentHash { get; set; }
419+
420+
[JsonProperty(PropertyName = "cycles_limit")]
421+
public string CyclesLimit { get; set; }
422+
423+
[JsonProperty(PropertyName = "bytes_limit")]
424+
public string BytesLimit { get; set; }
425+
426+
[JsonProperty(PropertyName = "uncles_count_limit")]
427+
public string UnclesCountLimit { get; set; }
428+
429+
[JsonProperty(PropertyName = "uncles")]
430+
public UncleTemplate[] Uncles { get; set; } = Array.Empty<UncleTemplate>();
431+
432+
[JsonProperty(PropertyName = "transactions")]
433+
public TransactionTemplate[] Transactions { get; set; } = Array.Empty<TransactionTemplate>();
434+
435+
[JsonProperty(PropertyName = "proposals")]
436+
public string[] Proposals { get; set; } = Array.Empty<string>();
437+
438+
[JsonProperty(PropertyName = "cellbase")]
439+
public CellbaseTemplate Cellbase { get; set; }
440+
441+
[JsonProperty(PropertyName = "work_id")]
442+
public string WorkId { get; set; }
443+
444+
[JsonProperty(PropertyName = "dao")]
445+
public string Dao { get; set; }
446+
}
354447
}

src/Tippy.Core/Data/TippyDbContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public TippyDbContext(DbContextOptions<TippyDbContext> options)
1313
public DbSet<Project> Projects { get; set; } = null!;
1414
public DbSet<Token> Tokens { get; set; } = null!;
1515
public DbSet<FailedTransaction> FailedTransactions { get; set; } = null!;
16+
public DbSet<DeniedTransaction> DeniedTransactions { get; set; } = null!;
1617

1718
protected override void OnModelCreating(ModelBuilder modelBuilder)
1819
{
@@ -33,6 +34,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3334
.HasOne(t => t.Project)
3435
.WithMany(p => p.FailedTransactions)
3536
.OnDelete(DeleteBehavior.Cascade);
37+
38+
modelBuilder.Entity<DeniedTransaction>()
39+
.HasOne(t => t.Project)
40+
.WithMany(p => p.DeniedTransactions)
41+
.OnDelete(DeleteBehavior.Cascade);
3642
}
3743
}
3844
}

src/Tippy.Core/Migrations/20210422045011_AddDeniedTransactions.Designer.cs

Lines changed: 202 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)