控制台从solidity函数记录双数组吗?

问题描述

正在进行chai测试,想从智能合约功能获取一个双精度数组,并对其进行控制台记录。 我的功能

function getBuyOrderBook(string symbolName) constant returns (uint[],uint[]) {
    uint8 tokenNameIndex = getSymbolIndexOrThrow(symbolName);
    uint[] memory arrPricesBuy = new uint[](tokens[tokenNameIndex].amountBuyPrices);//length of the prices
    uint[] memory arrVolumesBuy = new uint[](tokens[tokenNameIndex].amountBuyPrices);

       

        uint whilePrice = tokens[tokenNameIndex].lowestBuyPrice;
        uint counter = 0;
        if(tokens[tokenNameIndex].curBuyPrice > 0){ 
            while(whilePrice <= tokens[tokenNameIndex].curBuyPrice ){

                arrPricesBuy[counter] = whilePrice;
                
                uint volumeAtPrice = 0;

                uint offers_key = 0;
                offers_key = tokens[tokenNameIndex].buyBook[whilePrice].offers_key;

                while(tokens[tokenNameIndex].buyBook[whilePrice].offers_length >= offers_key){

                    volumeAtPrice += tokens[tokenNameIndex].buyBook[whilePrice].offers[offers_key].amount;//increase the amount(i.e. 10 tokens) to this price (i.e. 10$)
                    offers_key ++; //
                   
                }
                arrVolumesBuy[counter] = volumeAtPrice;
                if(whilePrice == tokens[tokenNameIndex].buyBook[whilePrice].higherPrice){ 

                    break;
                }
                else{
                    whilePrice == tokens[tokenNameIndex].buyBook[whilePrice].higherPrice ; 

                }
            counter ++; 

        }
           

            

    }

        return (arrPricesBuy,arrVolumesBuy ) ;


}

但不知道如何控制台记录诺言,因此我可以返回两个数组:

 let arr1 = [];
 let arr2 = [];

 arr1,arr2 =  await exchangeInstance.getArr(tokenSymbol);
 console.log(arr1,arr2);

这显然行不通,有什么建议吗?

谢谢

解决方法

对不起,伙计,我无法识别这是什么JavaScript语言子集,但是在纯JS中将是这样的:

function getBuyOrderBook(symbolName) {
  const arr1 = []; // our generated array 1
  const arr2 = []; // our generated array 2
  arr1.push.apply(arr1,[1,2,3]); // some operations with array 1
  arr2.push.apply(arr2,[4,5,6]); // some operations with array 2
  return [arr1,arr2]; // return combined result
}

let [a1,a2] = /*await*/ getBuyOrderBook(); // unpack result into 2 variables

console.log('a1 =',a1); // show var 1
console.log('a2 =',a2); // show var 2

这对您有意义吗?