MCPcopy Create free account
hub / github.com/SmartTokenLabs/TokenScript / getEthereumCallParams

Function getEthereumCallParams

bootstrap-js/modules/ts_helpers.js:351–422  ·  view source on GitHub ↗
({userAddress, tokenId, chainID , ethereumNode , xmlDoc, attributeName, tokenXmlNode, tokenName, debug})

Source from the content-addressed store, hash-verified

349 * @returns {boolean|{missedAttribute: *, contract: *, ethCallAttributtes: *, params: *}}
350 */
351export function getEthereumCallParams({userAddress, tokenId, chainID , ethereumNode , xmlDoc, attributeName, tokenXmlNode, tokenName, debug}){
352
353 let missedAttribute;
354
355 tokenId = tokenId ? tokenId : '';
356
357 // get default contract Name
358 let xmlNode = getXMLItem(xmlDoc,'ts:origins/ts:ethereum[1]', tokenXmlNode);
359 let defaultContract = xmlNode ? xmlNode.getAttribute('contract') : '';
360 defaultContract = defaultContract ? defaultContract : tokenName;
361
362 var params = [];
363
364 if (!ethereumNode) {
365 ethereumNode = getXMLItem(xmlDoc, 'ts:attribute[@name="' + attributeName + '"]/ts:origins/ethereum:call[1]', tokenXmlNode);
366 }
367
368 if (!ethereumNode) {
369 console.log('cant find attribute');
370 return false;
371 }
372
373 var atts = ethereumNode.getAttributeNames();
374 var ethCallAttributtes = {};
375 atts.forEach(attName=>{
376 ethCallAttributtes[attName] = ethereumNode.getAttribute(attName);
377 });
378
379 ethCallAttributtes.contract = ethCallAttributtes.contract ? ethCallAttributtes.contract : defaultContract;
380
381 var contract = getContractAddress(xmlDoc, ethCallAttributtes.contract, tokenXmlNode, chainID);
382
383 if (!contract.contractAddress) {
384 debug && console.log('Contract address required. chainID = '+chainID);
385 return false;
386 }
387
388 let nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
389 let xmlNodeSet = xmlDoc.evaluate('ts:data/*', ethereumNode, nsResolver, XPathResult.ANY_TYPE, null );
390
391 let item;
392
393 while (xmlNodeSet && (item = xmlNodeSet.iterateNext())){
394 let ref = item.getAttribute('ref');
395
396 switch (ref) {
397 case 'ownerAddress':
398 debug && console.log('ownerAddress = '+userAddress);
399 params.push(userAddress);
400 break;
401 case 'tokenId':
402 if(tokenId) {
403 params.push(tokenId);
404 } else {
405 missedAttribute = 'tokenId';
406 }
407 break;
408 default:

Callers 1

getPropsMethod · 0.90

Calls 2

getXMLItemFunction · 0.85
getContractAddressFunction · 0.85

Tested by

no test coverage detected