public TokenInfo TokenIdToTokenInfo(bool fungible, string tokenId, Int32 amount) { var tokenInfo = new TokenInfo(); tokenInfo.tokenType = tokenId.Substring(0, tokenId.Length - 8); tokenInfo.tokenIdx = tokenId.Substring(tokenId.Length - 8); tokenInfo.amount = amount; TokenTypeInfo tokenTypeInfo = null; if (fungible) { tokenTypeInfo = fungibleTypes.Find(x => x.tokenType == tokenInfo.tokenType); } else { tokenTypeInfo = nonFungibleTypes.Find(x => x.tokenType == tokenInfo.tokenType); } if (null != tokenTypeInfo) { tokenInfo.name = tokenTypeInfo.name; tokenInfo.meta = tokenTypeInfo.meta; } return(tokenInfo); }
void SetItemTokenType(List <TokenTypeInfo> tokenTypes, TokenTypeInfo tokenTypeInfo) { if (null == tokenTypes.Find(x => x.meta == tokenTypeInfo.meta)) { tokenTypes.Add(tokenTypeInfo); } else { logger.Warn($"Duplication TokenType TokenType={tokenTypeInfo.tokenType} meta={tokenTypeInfo.meta}"); } }
void GetLBDItemTokenIssue(string result) { var resDataHeader = JsonConvert.DeserializeObject <ResponesDataHeader>(result); if (resDataHeader.statusCode == 1000) { var code = TxHashToCode(result); var logs = TxHashToLogs(result); foreach (var log in logs) { if (code == 0) { foreach (var evnt in log.events) { switch (evnt.type) { case "issue_ft": { var tokenTypeInfo = new TokenTypeInfo(); foreach (var attr in evnt.attributes) { if (attr.key == "token_id") { tokenTypeInfo.tokenType = attr.value.Substring(0, attr.value.Length - 8); } else if (attr.key == "name") { tokenTypeInfo.name = attr.value; } } var msgInfo = GetTxMsg(result, log.msgIndex); if (msgInfo.Item1 == "collection/MsgIssueFT") { var msg = JsonConvert.DeserializeObject <IssueFTMsg>(msgInfo.Item2); if (null != msg) { tokenTypeInfo.meta = msg.value.meta; SetItemTokenType(fungibleTypes, tokenTypeInfo); } } else { logger.Warn($"{evnt.type} TxMsg Not equal Type={msgInfo.Item1}"); } } break; case "issue_nft": { var tokenTypeInfo = new TokenTypeInfo(); foreach (var attr in evnt.attributes) { if (attr.key == "token_type") { tokenTypeInfo.tokenType = attr.value; } } var msgInfo = GetTxMsg(result, log.msgIndex); if (msgInfo.Item1 == "collection/MsgIssueNFT") { var msg = JsonConvert.DeserializeObject <IssueNFTMsg>(msgInfo.Item2); if (null != msg) { tokenTypeInfo.name = msg.value.name; tokenTypeInfo.meta = msg.value.meta; SetItemTokenType(nonFungibleTypes, tokenTypeInfo); } } else { logger.Warn($"{evnt.type} TxMsg Not equal Type={msgInfo.Item1}"); } } break; } } } else { logger.Warn($"Log success fail log"); if (!string.IsNullOrEmpty(log.log)) { logger.Warn($"Code={code} {JValue.Parse(log.log).ToString(Formatting.Indented)}"); } else { logger.Warn($"Code={code} log is Empty"); } } } } else { logger.Warn($"Error statusCode={resDataHeader.statusCode} statusMessage={resDataHeader.statusMessage}"); } }