LCOV - code coverage report
Current view: top level - crypto/evm/entities/abi/erc - erc1155.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 76.9 % 26 20
Test Date: 2025-01-30 01:10:00 Functions: - 0 0

            Line data    Source code
       1              : import 'dart:typed_data';
       2              : 
       3              : import 'package:walletkit_dart/walletkit_dart.dart';
       4              : 
       5            3 : final contractAbiErc1155 = ContractABI.fromAbi('''[
       6              :   {
       7              :     "inputs": [
       8              :       {
       9              :         "internalType": "address",
      10              :         "name": "account",
      11              :         "type": "address"
      12              :       },
      13              :       {
      14              :         "internalType": "uint256",
      15              :         "name": "id",
      16              :         "type": "uint256"
      17              :       }
      18              :     ],
      19              :     "name": "balanceOf",
      20              :     "outputs": [
      21              :       {
      22              :         "internalType": "uint256",
      23              :         "name": "",
      24              :         "type": "uint256"
      25              :       }
      26              :     ],
      27              :     "stateMutability": "view",
      28              :     "type": "function"
      29              :   },
      30              :   {
      31              :     "inputs": [
      32              :       {
      33              :         "internalType": "address[]",
      34              :         "name": "accounts",
      35              :         "type": "address[]"
      36              :       },
      37              :       {
      38              :         "internalType": "uint256[]",
      39              :         "name": "ids",
      40              :         "type": "uint256[]"
      41              :       }
      42              :     ],
      43              :     "name": "balanceOfBatch",
      44              :     "outputs": [
      45              :       {
      46              :         "internalType": "uint256[]",
      47              :         "name": "",
      48              :         "type": "uint256[]"
      49              :       }
      50              :     ],
      51              :     "stateMutability": "view",
      52              :     "type": "function"
      53              :   },
      54              :   {
      55              :     "inputs": [
      56              :       {
      57              :         "internalType": "address",
      58              :         "name": "account",
      59              :         "type": "address"
      60              :       },
      61              :       {
      62              :         "internalType": "address",
      63              :         "name": "operator",
      64              :         "type": "address"
      65              :       }
      66              :     ],
      67              :     "name": "isApprovedForAll",
      68              :     "outputs": [
      69              :       {
      70              :         "internalType": "bool",
      71              :         "name": "",
      72              :         "type": "bool"
      73              :       }
      74              :     ],
      75              :     "stateMutability": "view",
      76              :     "type": "function"
      77              :   },
      78              :   {
      79              :     "inputs": [
      80              :       {
      81              :         "internalType": "address",
      82              :         "name": "from",
      83              :         "type": "address"
      84              :       },
      85              :       {
      86              :         "internalType": "address",
      87              :         "name": "to",
      88              :         "type": "address"
      89              :       },
      90              :       {
      91              :         "internalType": "uint256[]",
      92              :         "name": "ids",
      93              :         "type": "uint256[]"
      94              :       },
      95              :       {
      96              :         "internalType": "uint256[]",
      97              :         "name": "amounts",
      98              :         "type": "uint256[]"
      99              :       },
     100              :       {
     101              :         "internalType": "bytes",
     102              :         "name": "data",
     103              :         "type": "bytes"
     104              :       }
     105              :     ],
     106              :     "name": "safeBatchTransferFrom",
     107              :     "outputs": [],
     108              :     "stateMutability": "nonpayable",
     109              :     "type": "function"
     110              :   },
     111              :   {
     112              :     "inputs": [
     113              :       {
     114              :         "internalType": "address",
     115              :         "name": "from",
     116              :         "type": "address"
     117              :       },
     118              :       {
     119              :         "internalType": "address",
     120              :         "name": "to",
     121              :         "type": "address"
     122              :       },
     123              :       {
     124              :         "internalType": "uint256",
     125              :         "name": "id",
     126              :         "type": "uint256"
     127              :       },
     128              :       {
     129              :         "internalType": "uint256",
     130              :         "name": "amount",
     131              :         "type": "uint256"
     132              :       },
     133              :       {
     134              :         "internalType": "bytes",
     135              :         "name": "data",
     136              :         "type": "bytes"
     137              :       }
     138              :     ],
     139              :     "name": "safeTransferFrom",
     140              :     "outputs": [],
     141              :     "stateMutability": "nonpayable",
     142              :     "type": "function"
     143              :   },
     144              :   {
     145              :     "inputs": [
     146              :       {
     147              :         "internalType": "address",
     148              :         "name": "operator",
     149              :         "type": "address"
     150              :       },
     151              :       {
     152              :         "internalType": "bool",
     153              :         "name": "approved",
     154              :         "type": "bool"
     155              :       }
     156              :     ],
     157              :     "name": "setApprovalForAll",
     158              :     "outputs": [],
     159              :     "stateMutability": "nonpayable",
     160              :     "type": "function"
     161              :   },
     162              :   {
     163              :     "inputs": [
     164              :       {
     165              :         "internalType": "bytes4",
     166              :         "name": "interfaceId",
     167              :         "type": "bytes4"
     168              :       }
     169              :     ],
     170              :     "name": "supportsInterface",
     171              :     "outputs": [
     172              :       {
     173              :         "internalType": "bool",
     174              :         "name": "",
     175              :         "type": "bool"
     176              :       }
     177              :     ],
     178              :     "stateMutability": "view",
     179              :     "type": "function"
     180              :   },
     181              :   {
     182              :     "inputs": [
     183              :       {
     184              :         "internalType": "uint256",
     185              :         "name": "id",
     186              :         "type": "uint256"
     187              :       }
     188              :     ],
     189              :     "name": "uri",
     190              :     "outputs": [
     191              :       {
     192              :         "internalType": "string",
     193              :         "name": "",
     194              :         "type": "string"
     195              :       }
     196              :     ],
     197              :     "stateMutability": "view",
     198              :     "type": "function"
     199              :   },
     200              :   {
     201              :     "anonymous": false,
     202              :     "inputs": [
     203              :       {
     204              :         "indexed": true,
     205              :         "internalType": "address",
     206              :         "name": "account",
     207              :         "type": "address"
     208              :       },
     209              :       {
     210              :         "indexed": true,
     211              :         "internalType": "address",
     212              :         "name": "operator",
     213              :         "type": "address"
     214              :       },
     215              :       {
     216              :         "indexed": false,
     217              :         "internalType": "bool",
     218              :         "name": "approved",
     219              :         "type": "bool"
     220              :       }
     221              :     ],
     222              :     "name": "ApprovalForAll",
     223              :     "type": "event"
     224              :   },
     225              :   {
     226              :     "anonymous": false,
     227              :     "inputs": [
     228              :       {
     229              :         "indexed": true,
     230              :         "internalType": "address",
     231              :         "name": "operator",
     232              :         "type": "address"
     233              :       },
     234              :       {
     235              :         "indexed": true,
     236              :         "internalType": "address",
     237              :         "name": "from",
     238              :         "type": "address"
     239              :       },
     240              :       {
     241              :         "indexed": true,
     242              :         "internalType": "address",
     243              :         "name": "to",
     244              :         "type": "address"
     245              :       },
     246              :       {
     247              :         "indexed": false,
     248              :         "internalType": "uint256[]",
     249              :         "name": "ids",
     250              :         "type": "uint256[]"
     251              :       },
     252              :       {
     253              :         "indexed": false,
     254              :         "internalType": "uint256[]",
     255              :         "name": "values",
     256              :         "type": "uint256[]"
     257              :       }
     258              :     ],
     259              :     "name": "TransferBatch",
     260              :     "type": "event"
     261              :   },
     262              :   {
     263              :     "anonymous": false,
     264              :     "inputs": [
     265              :       {
     266              :         "indexed": true,
     267              :         "internalType": "address",
     268              :         "name": "operator",
     269              :         "type": "address"
     270              :       },
     271              :       {
     272              :         "indexed": true,
     273              :         "internalType": "address",
     274              :         "name": "from",
     275              :         "type": "address"
     276              :       },
     277              :       {
     278              :         "indexed": true,
     279              :         "internalType": "address",
     280              :         "name": "to",
     281              :         "type": "address"
     282              :       },
     283              :       {
     284              :         "indexed": false,
     285              :         "internalType": "uint256",
     286              :         "name": "id",
     287              :         "type": "uint256"
     288              :       },
     289              :       {
     290              :         "indexed": false,
     291              :         "internalType": "uint256",
     292              :         "name": "value",
     293              :         "type": "uint256"
     294              :       }
     295              :     ],
     296              :     "name": "TransferSingle",
     297              :     "type": "event"
     298              :   },
     299              :   {
     300              :     "anonymous": false,
     301              :     "inputs": [
     302              :       {
     303              :         "indexed": false,
     304              :         "internalType": "string",
     305              :         "name": "value",
     306              :         "type": "string"
     307              :       },
     308              :       {
     309              :         "indexed": true,
     310              :         "internalType": "uint256",
     311              :         "name": "id",
     312              :         "type": "uint256"
     313              :       }
     314              :     ],
     315              :     "name": "URI",
     316              :     "type": "event"
     317              :   }
     318              : ]
     319              : 
     320              : ''');
     321              : 
     322              : class ERC1155Contract extends InternalContract {
     323            1 :   ERC1155Contract({
     324              :     required super.contractAddress,
     325              :     required super.rpc,
     326            1 :   }) : super(
     327            1 :           abi: contractAbiErc1155,
     328              :         );
     329              : 
     330            1 :   Future<BigInt> balanceOf({
     331              :     required String address,
     332              :     required BigInt tokenID,
     333              :   }) async {
     334            3 :     final function = abi.functions[0];
     335            1 :     final response = await readSafe(
     336            2 :       function: function.addValues(values: [address, tokenID]),
     337              :     );
     338            3 :     return response.outputs.first.castValue<BigInt>();
     339              :   }
     340              : 
     341            1 :   Future<List<BigInt>> balanceOfBatch({
     342              :     required List<String> accounts,
     343              :     required List<BigInt> tokenIDs,
     344              :   }) async {
     345            3 :     if (accounts.length != tokenIDs.length) {
     346            0 :       throw ArgumentError('accounts and tokenIDs must have the same length');
     347              :     }
     348            3 :     final function = abi.functions[1];
     349            1 :     final response = await readSafe(
     350            2 :       function: function.addValues(values: [accounts, tokenIDs]),
     351              :     );
     352            3 :     return response.outputs.first.castValue<List<BigInt>>();
     353              :   }
     354              : 
     355            1 :   Future<String> getUri({
     356              :     required BigInt tokenID,
     357              :   }) async {
     358            3 :     final function = abi.functions[7];
     359            1 :     final response = await readSafe(
     360            2 :       function: function.addValues(values: [tokenID]),
     361              :     );
     362            3 :     return response.outputs.first.castValue<String>();
     363              :   }
     364              : 
     365            0 :   Future<String> safeTransferFrom({
     366              :     required String sender,
     367              :     required String to,
     368              :     required BigInt tokenID,
     369              :     required BigInt amount,
     370              :     required Uint8List seed,
     371              :     Uint8List? data,
     372              :     EvmFeeInformation? feeInfo,
     373              :     List<AccessListItem>? accessList,
     374              :   }) async {
     375            0 :     final function = abi.functions[4];
     376            0 :     return await interact(
     377            0 :       function: function.addValues(
     378            0 :           values: [sender, to, tokenID, amount, data ?? Uint8List(0)]),
     379              :       sender: sender,
     380              :       seed: seed,
     381              :       feeInfo: feeInfo,
     382              :       accessList: accessList,
     383              :     );
     384              :   }
     385              : }
        

Generated by: LCOV version 2.0-1