本文整理汇总了C#中ByteString.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ByteString.ToString方法的具体用法?C# ByteString.ToString怎么用?C# ByteString.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteString
的用法示例。
在下文中一共展示了ByteString.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMutation
public async Task<Mutation> GetMutation(ByteString hash)
{
Mutation mutation;
if (!Transactions.TryGetValue(hash, out mutation))
{
string account = $"/asset/{assetName}/out/";
string asset = $"/asset/{assetName}/";
HttpClient client = new HttpClient();
HttpResponseMessage getTransactionResponse = await client.GetAsync(new Uri(openChainUri, $"query/transaction?mutation_hash={hash.ToString()}"));
JToken rawTransaction = JToken.Parse(await getTransactionResponse.EnsureSuccessStatusCode().Content.ReadAsStringAsync());
Transaction transaction = MessageSerializer.DeserializeTransaction(ByteString.Parse((string)rawTransaction["raw"]));
mutation = MessageSerializer.DeserializeMutation(transaction.Mutation);
Transactions.Add(hash, mutation);
}
return mutation;
}
示例2: MoveToRedemption
public async Task MoveToRedemption(IList<OutboundTransaction> transactions, ByteString btcTransaction)
{
List<Record> records = new List<Record>();
foreach (OutboundTransaction transaction in transactions)
{
// TODO: Allow double spending
records.Add(new Record(
key: Encode($"/asset/{assetName}/tx/:DATA:{transaction.Version.ToString()}"),
value: Encode(JObject.FromObject(new { transactions = new[] { btcTransaction.ToString() } }).ToString()),
version: ByteString.Empty));
records.Add(new Record(
key: transaction.RecordKey,
value: ByteString.Empty,
version: transaction.Version));
}
HttpClient client = new HttpClient();
ByteString finalKey = Encode($"/asset/{assetName}/final/:ACC:/asset/{assetName}/");
HttpResponseMessage getValueResponse = await client.GetAsync(new Uri(openChainUri, $"record?key={finalKey.ToString()}"));
string stringResponse = await getValueResponse.EnsureSuccessStatusCode().Content.ReadAsStringAsync();
ByteString finalVersion = ByteString.Parse((string)JObject.Parse(stringResponse)["version"]);
long currentValue = ParseInt(ByteString.Parse((string)JObject.Parse(stringResponse)["value"]));
records.Add(new Record(
key: finalKey,
value: Encode(currentValue + transactions.Sum(transaction => transaction.Amount)),
version: finalVersion));
Mutation mutation = new Mutation(Encode(this.openChainUri.ToString()), records, ByteString.Empty);
byte[] serializedMutation = MessageSerializer.SerializeMutation(mutation);
await SignAndSubmit(serializedMutation);
}
示例3: DecodeRespTextString
private string DecodeRespTextString(ByteString text)
{
/*
* RFC 5255 - Internet Message Access Protocol Internationalization
* http://tools.ietf.org/html/rfc5255
* 3.5. Formal Syntax
* resp-text = ["[" resp-text-code "]" SP ] UTF8-TEXT-CHAR
* *(UTF8-TEXT-CHAR / "[")
* ; After the server is changed to a language other than
* ; i-default, this resp-text rule replaces the resp-text
* ; rule from [RFC3501].
*/
if (ReceiveResponseAsUTF8)
return Encoding.UTF8.GetString(text.ByteArray);
else
return text.ToString();
}
示例4: GetKeyStartingFrom
public Task<IReadOnlyList<Record>> GetKeyStartingFrom(ByteString prefix)
{
return Task.FromResult((IReadOnlyList<Record>)records.Where(record => record.Key.ToString().StartsWith(prefix.ToString())).ToList());
}
示例5: ParseResponce
private ImapResponse ParseResponce(ByteString line, ref IParsingContext parsingContext)
{
// response = *(continue-req / response-data) response-done
// continue-req = "+" SP (resp-text / base64) CRLF
if (line.StartsWith(continueReqMark))
return new ImapCommandContinuationRequest(line.ToString(2, line.Length - 4)); // remove leading "+" SP and trailing CRLF
// greeting = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
// response-done = response-tagged / response-fatal
// response-data = "*" SP (resp-cond-state / resp-cond-bye /
// mailbox-data / message-data / capability-data) CRLF
// response-fatal = "*" SP resp-cond-bye CRLF
// ; Server closes connection immediately
// response-tagged = tag SP resp-cond-state CRLF
// ("*" / tag) SP
var tagSep = line.IndexOf(Octets.SP);
if (tagSep == -1)
// response-done and response-data must contain SP
throw new ImapMalformedResponseException("malformed response-done/response-data", line.ToString());
var untagged = (tagSep == 1 && line[0] == ImapOctets.Asterisk);
// ("OK" / "BAD" / "NO" / "BYE" / "PREAUTH" / text) SP
var respCondSep = line.IndexOf(Octets.SP, tagSep + 1);
var cond = ImapResponseCondition.Undefined;
if (respCondSep == -1) {
if (!untagged)
throw new ImapMalformedResponseException("malformed response-data", line.ToString());
//else
// '* SEARCH\r\n' (mailbox-data which contains no SP)
}
else {
cond = ParseCondition(line.Substring(tagSep + 1, respCondSep - tagSep - 1));
}
if (cond != ImapResponseCondition.Undefined || line.StartsWith(respCondMark)) {
// resp-cond-auth / resp-cond-state / resp-cond-bye
var responseText = ParseRespText((cond == ImapResponseCondition.Undefined)
? line.Substring(tagSep + 1)
: line.Substring(respCondSep + 1));
if (untagged)
return new ImapUntaggedStatusResponse((ImapResponseCondition)cond,
responseText);
else
return new ImapTaggedStatusResponse(line.ToString(0, tagSep),
(ImapResponseCondition)cond,
responseText);
}
// mailbox-data / message-data / capability-data etc.
return ParseDataResponse(line, ref parsingContext);
}
示例6: TestToStringPartial
public void TestToStringPartial()
{
var str = new ByteString("abcdefghi");
Assert.AreEqual("abcdefghi", str.ToString(0));
Assert.AreEqual("", str.ToString(0, 0));
Assert.AreEqual("abc", str.ToString(0, 3));
Assert.AreEqual("abcdefghi", str.ToString(0, 9));
Assert.AreEqual("defghi", str.ToString(3));
Assert.AreEqual("", str.ToString(3, 0));
Assert.AreEqual("def", str.ToString(3, 3));
Assert.AreEqual("defghi", str.ToString(3, 6));
Assert.AreEqual("i", str.ToString(8, 1));
}
示例7: TestToString
public void TestToString()
{
var str = new ByteString(0x61, 0x62, 0x63);
Assert.AreEqual("abc", str.ToString());
}
示例8: ToString
public static string ToString(ByteString text)
{
return text.ToString();
}
示例9: SubmitTransaction
private async Task<ByteString> SubmitTransaction(ByteString transaction)
{
using (HttpClient client = new HttpClient())
{
StringContent content = new StringContent($"\"{transaction.ToString()}\"");
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = await client.PostAsync(new Uri(url, "sendrawtransaction"), content);
response.EnsureSuccessStatusCode();
JToken result = JToken.Parse(await response.Content.ReadAsStringAsync());
return ByteString.Parse((string)result);
}
}