Last active
November 6, 2018 09:40
-
-
Save soichisumi/c84cf7543822571f45df8bfc15cbbeed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jayson-promise-test | |
const jayson = require(`jayson/promise`); | |
const client = jayson.client.https(`http://url`); | |
client.request(`sendrawtransaction`, [`02000000000101e704a7202bd63642b45234d1d132fcd72112789a1caa08c3b6843d7d2e94b211010000001716001421aa1728d096147222c201519a8710fd1bc2f416ffffffff01405489000000000017a91400853f1aefada64964a3f602846d263f5f3630a98702483045022100dc5051daf71e46c4e297e66c4b71f8d2fb3359dc209f24ca598677215318867502203b131875c948dd996a0575b0600e3b702d29de9ac7853c388319e20babe2d7b00121038bf0cde309b16f3513725515f077178e8ff8b89269543555057edc28b16179cd00000000`]) | |
.then((res)=>{console.log(JSON.stringify(res))}) | |
.catch((err)=> { | |
console.log(JSON.stringify(err)); | |
console.log(String(err)); | |
if(String(err).startsWith(‘Error: ’)){ | |
const str = String(err).slice(7); | |
console.log(str); | |
const errObj = JSON.parse(str); | |
console.log(`res:`); | |
console.log(`error: ${errObj.error}`); | |
console.log(`id: ${errObj.id}`); | |
console.log(errObj); | |
} | |
}); | |
// String(err) | |
// ↓ | |
// Error: {“result”:null,“error”:{“code”:-27,“message”:“transaction already in block chain”},“id”:“0bbc099c-9961-435f-9332-7b5406ae764f”} | |
// 最初の Error: は何 型がstringでヤバイ | |
// JSON.stringify(err) | |
// ↓ | |
// {“code”:500} | |
// なんでcodeだけやねん |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rp = require(`request-promise`); | |
const option = { | |
method: `POST`, | |
uri: `url`, | |
body: { | |
id: 1, | |
method: `sendrawtransaction`, | |
params: [`02000000000101e704a7202bd63642b45234d1d132fcd72112789a1caa08c3b6843d7d2e94b211010000001716001421aa1728d096147222c201519a8710fd1bc2f416ffffffff01405489000000000017a91400853f1aefada64964a3f602846d263f5f3630a98702483045022100dc5051daf71e46c4e297e66c4b71f8d2fb3359dc209f24ca598677215318867502203b131875c948dd996a0575b0600e3b702d29de9ac7853c388319e20babe2d7b00121038bf0cde309b16f3513725515f077178e8ff8b89269543555057edc28b16179cd00000000`] | |
}, | |
json: true | |
}; | |
rp(option).then((res)=>{ | |
console.log(`res: ${res.error}`); | |
}).catch(err => { | |
console.log(`err: ${JSON.stringify(err.error)}`); | |
}) | |
// JSON.stringify(err) | |
// ↓ | |
// err: {“name”:“StatusCodeError”,“statusCode”:500,“message”:“500 - {\“result\“:null,\“error\“:{\“code\“:-27,\“message\“:\“transaction already in block chain\“},\“id\“:1}“,”error”:{“result”:null,“error”:{“code”:-27,“message”:“transaction already in block chain”},“id”:1},“options”:{“method”:“POST”,“uri”:“https://daikokuten:[email protected]”,“body”:{“id”:1,“method”:“sendrawtransaction”,“params”:[“02000000000101e704a7202bd63642b45234d1d132fcd72112789a1caa08c3b6843d7d2e94b211010000001716001421aa1728d096147222c201519a8710fd1bc2f416ffffffff01405489000000000017a91400853f1aefada64964a3f602846d263f5f3630a98702483045022100dc5051daf71e46c4e297e66c4b71f8d2fb3359dc209f24ca598677215318867502203b131875c948dd996a0575b0600e3b702d29de9ac7853c388319e20babe2d7b00121038bf0cde309b16f3513725515f077178e8ff8b89269543555057edc28b16179cd00000000”]},“json”:true,“simple”:true,“resolveWithFullResponse”:false,“transform2xxOnly”:false},“response”:{“statusCode”:500,“body”:{“result”:null,“error”:{“code”:-27,“message”:“transaction already in block chain”},“id”:1},“headers”:{“content-type”:“application/json”,“date”:“Tue, 06 Nov 2018 09:21:05 GMT”,“content-length”:“91”,“via”:“1.1 google”,“alt-svc”:“clear”,“connection”:“close”},“request”:{“uri”:{“protocol”:“https:“,”slashes”:true,“auth”:“daikokuten:QFuKypZKB3spqmFqcqsPpw8R”,“host”:“bitcoind-testnet-develop.ginco.company”,“port”:443,“hostname”:“bitcoind-testnet-develop.ginco.company”,“hash”:null,“search”:null,“query”:null,“pathname”:“/”,“path”:“/”,“href”:“https://daikokuten:[email protected]/“},“method”:“POST”,“headers”:{“authorization”:“Basic ZGFpa29rdXRlbjpRRnVLeXBaS0Izc3BxbUZxY3FzUHB3OFI=“,”accept”:“application/json”,“content-type”:“application/json”,“content-length”:484}}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment