Any.fromJson constructor
Create a new Any instance by parsing a JSON map.
Implementation
factory Any.fromJson(Map<String, dynamic> json) {
final String typeUrl =
OnChainUtils.parseString(value: json["type_url"], name: "type_url");
final parts = typeUrl.split("type.googleapis.com/protocol.");
if (parts.length != 2) {
throw const TronPluginException("Invalid contract typeUrl");
}
final contractType = TransactionContractType.findByName(parts.last);
final Map<String, dynamic> contractDetails = OnChainUtils.parseMap(
value: json["value"], name: "value", throwOnNull: true)!;
TronBaseContract contract;
switch (contractType) {
case TransactionContractType.transferContract:
contract = TransferContract.fromJson(contractDetails);
break;
case TransactionContractType.assetIssueContract:
contract = AssetIssueContract.fromJson(contractDetails);
break;
case TransactionContractType.cancelAllUnfreezeV2Contract:
contract = CancelAllUnfreezeV2Contract.fromJson(contractDetails);
break;
case TransactionContractType.updateAssetContract:
contract = UpdateAssetContract.fromJson(contractDetails);
break;
case TransactionContractType.participateAssetIssueContract:
contract = ParticipateAssetIssueContract.fromJson(contractDetails);
break;
case TransactionContractType.transferAssetContract:
contract = TransferAssetContract.fromJson(contractDetails);
break;
case TransactionContractType.accountCreateContract:
contract = AccountCreateContract.fromJson(contractDetails);
break;
case TransactionContractType.accountUpdateContract:
contract = AccountUpdateContract.fromJson(contractDetails);
break;
case TransactionContractType.freezeBalanceV2Contract:
contract = FreezeBalanceV2Contract.fromJson(contractDetails);
break;
case TransactionContractType.unfreezeBalanceV2Contract:
contract = UnfreezeBalanceV2Contract.fromJson(contractDetails);
break;
case TransactionContractType.withdrawBalanceContract:
contract = WithdrawBalanceContract.fromJson(contractDetails);
break;
case TransactionContractType.withdrawExpireUnfreezeContract:
contract = WithdrawExpireUnfreezeContract.fromJson(contractDetails);
break;
case TransactionContractType.delegateResourceContract:
contract = DelegateResourceContract.fromJson(contractDetails);
break;
case TransactionContractType.unDelegateResourceContract:
contract = UnDelegateResourceContract.fromJson(contractDetails);
break;
case TransactionContractType.unfreezeBalanceContract:
contract = UnfreezeBalanceContract.fromJson(contractDetails);
break;
case TransactionContractType.freezeBalanceContract:
contract = FreezeBalanceContract.fromJson(contractDetails);
break;
case TransactionContractType.accountPermissionUpdateContract:
contract = AccountPermissionUpdateContract.fromJson(contractDetails);
break;
case TransactionContractType.triggerSmartContract:
contract = TriggerSmartContract.fromJson(contractDetails);
break;
case TransactionContractType.createSmartContract:
contract = CreateSmartContract.fromJson(contractDetails);
break;
case TransactionContractType.setAccountIdContract:
contract = SetAccountIdContract.fromJson(contractDetails);
break;
case TransactionContractType.exchangeCreateContract:
contract = ExchangeCreateContract.fromJson(contractDetails);
break;
case TransactionContractType.exchangeInjectContract:
contract = ExchangeInjectContract.fromJson(contractDetails);
break;
case TransactionContractType.exchangeTransactionContract:
contract = ExchangeTransactionContract.fromJson(contractDetails);
break;
case TransactionContractType.exchangeWithdrawContract:
contract = ExchangeWithdrawContract.fromJson(contractDetails);
break;
case TransactionContractType.marketCancelOrderContract:
contract = MarketCancelOrderContract.fromJson(contractDetails);
break;
case TransactionContractType.marketSellAssetContract:
contract = MarketSellAssetContract.fromJson(contractDetails);
break;
case TransactionContractType.proposalApproveContract:
contract = ProposalApproveContract.fromJson(contractDetails);
break;
case TransactionContractType.proposalCreateContract:
contract = ProposalCreateContract.fromJson(contractDetails);
break;
case TransactionContractType.proposalDeleteContract:
contract = ProposalDeleteContract.fromJson(contractDetails);
break;
case TransactionContractType.shieldedTransferContract:
contract = ShieldedTransferContract.fromJson(contractDetails);
break;
case TransactionContractType.clearABIContract:
contract = ClearABIContract.fromJson(contractDetails);
break;
case TransactionContractType.updateEnergyLimitContract:
contract = UpdateEnergyLimitContract.fromJson(contractDetails);
break;
case TransactionContractType.updateSettingContract:
contract = UpdateSettingContract.fromJson(contractDetails);
break;
case TransactionContractType.updateBrokerageContract:
contract = UpdateBrokerageContract.fromJson(contractDetails);
break;
case TransactionContractType.voteAssetContract:
contract = VoteAssetContract.fromJson(contractDetails);
break;
case TransactionContractType.voteWitnessContract:
contract = VoteWitnessContract.fromJson(contractDetails);
break;
case TransactionContractType.unfreezeAssetContract:
contract = UnfreezeAssetContract.fromJson(contractDetails);
break;
case TransactionContractType.witnessUpdateContract:
contract = WitnessUpdateContract.fromJson(contractDetails);
break;
case TransactionContractType.witnessCreateContract:
contract = WitnessCreateContract.fromJson(contractDetails);
break;
default:
throw TronPluginException("Unsupported contract",
details: {"contract": contractType.name});
}
return Any(typeUrl: typeUrl, value: contract);
}