web3 RPC连接终止没有输出的程序

时间:2018-10-31 18:09:50

标签: javascript async-await web3

我有一个简单的NodeJS程序来演示我的问题

<div class='w3-row'> <div class='w3-twothird w3-container'>
 <div class='w3-content' style='max-width:400px;position:relative'>
  <img src='http://www.kibao.org/img/bao14a.png' style='width:100%; display: block;'>
 </div>
</div>
<div class='w3-third w3-container'>
 <div class='w3-content' style='max-width:500px'>
  <div class='w3-cell-row'>                                                  
   <div class='w3-container'>
    <div class='w3-cell'>&nbsp;&nbsp;</div>
    <div class='w3-cell'>8&nbsp;</div>
    <div class='w3-cell'>7&nbsp;</div>
    <div class='w3-cell'>6&nbsp;</div>
    <div class='w3-cell'>5&nbsp;</div>
    <div class='w3-cell'>4&nbsp;</div>
    <div class='w3-cell'>3&nbsp;</div>
    <div class='w3-cell'>2&nbsp;</div>
    <div class='w3-cell'>1</div>
   </div> 
   <div class='w3-container'>
    <div class='w3-cell'>b&nbsp;</div>
    <div class='w3-cell'>5&nbsp;</div>
    <div class='w3-cell'>0&nbsp;</div>
    <div class='w3-cell'>4&nbsp;</div>
    <div class='w3-cell'>1&nbsp;</div>
    <div class='w3-cell'>2&nbsp;</div>
    <div class='w3-cell'>3&nbsp;</div>
    <div class='w3-cell'>0&nbsp;</div>
    <div class='w3-cell'>0</div>
   </div> 
  <div class='w3-container'>
   <div class='w3-cell'>a&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>5&nbsp;</div>
   <div class='w3-cell'>5&nbsp;</div>
   <div class='w3-cell'>6&nbsp;</div>
   <div class='w3-cell'>3&nbsp;</div>
   <div class='w3-cell'>0</div>
  </div>      
  <div class='w3-container'>                                                    
   <div class='w3-cell'>A&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>3&nbsp;</div>
   <div class='w3-cell'>2&nbsp;</div>
   <div class='w3-cell'>1&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>4&nbsp;</div>
   <div class='w3-cell'>1&nbsp;</div>
   <div class='w3-cell'>0</div>
  </div>      
  <div class='w3-container'>
   <div class='w3-cell'>B&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>9&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>3&nbsp;</div>
   <div class='w3-cell'>1&nbsp;</div>
   <div class='w3-cell'>0&nbsp;</div>
   <div class='w3-cell'>1&nbsp;</div>
   <div class='w3-cell'>0</div>
  </div>      
  <div class='w3-container'>
   <div class='w3-cell'>&nbsp;&nbsp;</div>
   <div class='w3-cell'>1&nbsp;</div>
   <div class='w3-cell'>2&nbsp;</div>
   <div class='w3-cell'>3&nbsp;</div>
   <div class='w3-cell'>4&nbsp;</div>
   <div class='w3-cell'>5&nbsp;</div>
   <div class='w3-cell'>6&nbsp;</div>
   <div class='w3-cell'>7&nbsp;</div>
   <div class='w3-cell'>8</div>
  </div> 
 </div>
</div>

我正在使用: “ truffle-hdwallet-provider”:“ 0.0.6”, “ web3”:“ ^ 1.0.0-beta.36”

当我运行该程序时,“通过”或“失败”都不会打印到屏幕上。我不知道发生了什么,程序如何才能结束但没有错误(进入catch块并打印失败)或继续并打印“通过”。

1 个答案:

答案 0 :(得分:0)

Documentation表示此方法,您必须提供回调方法或使用function LoginAuth0 { LogAction 'Logging into Auth0' $url = BnUrl('/auth/login?fromSignIn=True') $login = Invoke-WebRequest $url -UseBasicParsing -SessionVariable Script:session -Method 'GET' $match = [regex]::Match($login.Content, "var config = JSON\.parse\(decodeURIComponent\(escape\(window.atob\('([a-zA-Z0-9=]+)'\)\)\)\);") if($match.Success) { $configDataBase64 = $match.captures.groups[1].value } if( -not $configDataBase64 ) { LogError('Could not get config data'); Exit 1 } $configDataUriEncoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($configDataBase64)) $configDecoded = [System.Web.HttpUtility]::UrlDecode($configDataUriEncoded) $lockConfig = ($configDecoded | ConvertFrom-Json) $fields = @{ 'redirect_uri' = BnUrl('/signin-auth0') 'tenant' = $Script:config.auth0_tenant 'response_type' = 'code id_token' 'connection' = 'Username-Password-Authentication' 'sso' = 'true' 'response_mode' = 'form_post' '_intstate' = 'deprecated' 'allow_signup' = 'false' 'x-client-_sku' = 'ID_NET461' 'allow_login' = 'true' 'scope' = 'openid profile' 'x-client-ver' = '5.3.0.0' 'protocol' = 'oauth2' 'client_id' = $lockConfig.clientID 'username' = $Script:config.site_user 'password' = $Script:config.site_pass '_csrf' = $lockConfig.internalOptions._csrf 'nonce' = $lockConfig.internalOptions.nonce 'state' = $lockConfig.internalOptions.state } $post_url = "https://$($Script:config.auth0_tenant).auth0.com/usernamepassword/login" $post_json = Invoke-WebRequest $post_url -UseBasicParsing -WebSession $Script:session -Method 'POST' -ContentType 'application/json' -Body ($fields|ConvertTo-Json) $match = [regex]::Match($post_json.Content, '<input\s+type="\w+"\s+name="wresult"\s+value="([^>]+)">') if( -not $match.Success ) { LogError('Could not find wresult') Exit 1 } $wresult = $match.captures.groups[1].value $match = [regex]::Match($post_json.Content, '<input\s+type="\w+"\s+name="wctx"\s+value="([^>]+)">') if( -not $match.Success ) { LogError('Could not find wctx') Exit 1 } $wctx = $match.captures.groups[1].value -replace '&#34;','"' | ConvertFrom-Json $formFields = @{ wa = 'wsignin1.0' wresult = $wresult wctx = $wctx | ConvertTo-Json -Compress } $url = "https://$($Script:config.auth0_tenant).auth0.com/login/callback" $post_form = Invoke-WebRequest $url -UseBasicParsing -WebSession $Script:session -Method 'POST' -ContentType 'application/x-www-form-urlencoded' -Body $formFields $match = [regex]::Match($post_form.Content, '<input\s+type="\w+"\s+name="code"\s+value="([^>]+)"\s*/>') if( -not $match.Success ) { LogError('Could not find code') Exit 1 } $code = $match.captures.groups[1].value $match = [regex]::Match($post_form.Content, '<input\s+type="\w+"\s+name="id_token"\s+value="([^>]+)"\s*/>') if( -not $match.Success ) { LogError('Could not find code') Exit 1 } $token = $match.captures.groups[1].value $match = [regex]::Match($post_form.Content, '<input\s+type="\w+"\s+name="state"\s+value="([^>]+)"\s*/>') if( -not $match.Success ) { LogError('Could not find code') Exit 1 } $state = $match.captures.groups[1].value $formFields = @{ code = $code id_token = $token state = $state } $url = BnUrl('/signin-auth0') $result = Invoke-WebRequest $url -UseBasicParsing -WebSession $Script:session -Method 'POST' -ContentType 'application/x-www-form-urlencoded' -Body $formFields if($result.StatusCode -eq 200) { LogOk } else { LogError('failed to login') Exit 1 } } 属性来同步执行。您的示例如下所示:

web3.eth.coinbase

可能是您收到了运行时错误,但没有注意到它。