한 3일 삽질 한거 같은데 잘 안된다.

 

어제 자바스크립트 5만줄짜리 분석해보고 코딩 한줄도 못하고

오늘 다시 TronLink부터 차근 차근 분석 해볼려구 한다.

 

오늘 안에 제발 완료 되면 좋겠다.

 

시간은 잘 가서 좋긴한데 ㅎ

조금 답답한 면도 있다.

 

 

https://apilist.tronscan.org/api/account?address=TRWkuqvtjc6FXsbJhpnJNG7bB6CAwu6dfM

 

결과 json은 아래에서 파싱 하면 된다.

https://jsoneditoronline.org/

 

정말 허무하다.

아무거나 마음에 드는거 쓰면 된다.

router.get('/tokenBalance/:Address',function(req,res,next) {
 const app = async () => {
         try {
                const Add = req.params.Address;
                const gBalance = await tronWeb.trx.getAccount(Add);
                var token = gBalance.assetV2[0].value;
                res.json( { "getBalance  ": token})

                }catch (error) { console.log('Task Failure',error);
                }
        };
app();
});

 

블로그 이미지

iesay

nodejs - form submit

시스템 2019.01.22 11:33

새로고침 없는 비동기로 새로운 방식이라고 한다.

 

 

nodejs - form submit

 

app.js


const express = require('express');
const app = express();
const bodyParser = require('body-parser');

app.use(express.static('public'));
app.use(bodyParser.urlencoded({extended: true}));

app.get('/', (req, res) => {
    res.sendfile('public/index.html');
});

app.post('/login', (req, res) => {
        console.log(req.body.userId, req.body.userPw);
    if(req.body.userId==='admin'&&req.body.userPw==='1234'){
        res.json({success:true});
    }else{
        res.json({success:false});
    }
});

app.listen(8000);

console.log("open 8000");


module.exports = app;


 

 

public/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="//code.jquery.com/jquery-latest.min.js"></script>
    <title>Hello</title>
    <script>
        $(document).ready(function (){
            $('#login').click(function () {
                $.ajax({
                    url: 'http://192.168.0.118:8000/login',
                    method : 'POST',
                    data: {userId : $('#id').val(), userPw: $('#pw').val()},
                    dataType: 'json'
                }).done(function(data){
                    if(data.success)
                        alert('로그인 성공');
                    else
                        alert('로그인 실패');
                }).fail(function (data){
                    alert('로그인 오류');
                })
            });
        });
    </script>
</head>
<body>
    <h1>로그인페이지</h1>
    <hr>
    아이디 <input type="text" id='id'>
    패스워드 <input type="password" id='pw'>
    <button id="login">로그인</button>

</body>
</html>

 

실행 결과

 

미들웨어 처리 함

root@tkpark-VirtualBox:~/project/myapp# yarn start
yarn run v1.13.0
$ node ./bin/www
open 8000
admin 1234
admin 1
admin 1
admin 1234
admin 1234

 

 

http://192.168.0.118:8000/

이제 기존의 route랑 연동해야겠다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'시스템' 카테고리의 다른 글

nodejs - form submit  (0) 2019.01.22
nodejs + mariadb 연동  (0) 2019.01.14
nodejs json파일 MongDB에 입력  (0) 2018.12.04
nodejs json파일 컨트롤  (0) 2018.12.04
Mongdb 설치 ubuntu 18  (0) 2018.11.30
리눅스 node-gyp 에러 error  (0) 2018.11.23
블로그 이미지

iesay

출처 : https://gist.github.com/aunyks/8f2c2fd51cc17f342737917e1c2582e2

 

ex1.js 돌아는 간다.


const date = require('date-utils');
var dt = new Date();

 


var Block = new function(){
                this.index = 0;
                this.timestamp = dt.clone();
                this.data = "data :  Genesis Block"
                this.previous_hash = "0";
                this.hash = crypto.createHash("sha256").update(this.index + this.timestamp + this.data + this.previous_hash).digest("hex");
};


console.log("index : ", Block.index, "timestamp : ", Block.timestamp, "data : ", Block.data, "previous_hash : ", Block.previous_hash, "hash", Block.hash);

const next_block = async () => {
        try{
        Block.index = Block.index+1;
        Block.timestamp = dt.clone();
        Block.data = "Hey! I'm block " + Block.index;
        Block.previous_hash = Block.hash;
        Block.hash = crypto.createHash("sha256").update(Block.index + Block.timestamp + Block.data + Block.previous_hash).digest("hex");
        }catch (error) { console.log('Task Failure',error);}
}


var num_of_blocks_to_add = 20;

for(var i=0; i<num_of_blocks_to_add; i++){
        next_block();
        console.log("index : ", Block.index, "timestamp : ", Block.timestamp, "data : ", Block.data, "previous_hash : ", Block.previous_hash, "hash", Block.hash);
}
 

 

 

 

실행결과

root@tkpark-VirtualBox:~/project/myapp/routes# nodejs ex1.js
index :  0 timestamp :  2019-01-17T06:14:00.735Z data :  data :  Genesis Block previous_hash :  0 hash 435f39b1283eaaad92378228feb0ff217904cba051828ddbf87eb9049fc269fc
index :  1 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 1 previous_hash :  435f39b1283eaaad92378228feb0ff217904cba051828ddbf87eb9049fc269fc hash ea0b1c93cff5ad20bd1b300f339e557747cf92f9cccf18839069b9b34df40241
index :  2 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 2 previous_hash :  ea0b1c93cff5ad20bd1b300f339e557747cf92f9cccf18839069b9b34df40241 hash 27cd8f270c2d09ad2e7409f50ce9dd29d5141cfc1c62dcc2c189f7f7ad394ed1
index :  3 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 3 previous_hash :  27cd8f270c2d09ad2e7409f50ce9dd29d5141cfc1c62dcc2c189f7f7ad394ed1 hash dd12e07c03dd274850ed7071fe6e3009758c56361fcc6d64ca3befed4f683ab7
index :  4 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 4 previous_hash :  dd12e07c03dd274850ed7071fe6e3009758c56361fcc6d64ca3befed4f683ab7 hash efc128e74d5e32f761d11e63851431c84564b315f1ad2cf96e9b610f43a35a74
index :  5 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 5 previous_hash :  efc128e74d5e32f761d11e63851431c84564b315f1ad2cf96e9b610f43a35a74 hash 3bfb7ea0d0ae3183240976de82c100d7f83ce11a91faa6a2b5c79d4a889b525b
index :  6 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 6 previous_hash :  3bfb7ea0d0ae3183240976de82c100d7f83ce11a91faa6a2b5c79d4a889b525b hash 93e60df16e258ba4e40407f68a13763db2e741129ef15fa25b5d4c5f98d13f29
index :  7 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 7 previous_hash :  93e60df16e258ba4e40407f68a13763db2e741129ef15fa25b5d4c5f98d13f29 hash dc3bd4fb62dfb15ad82e44b3768e4bc03a2085efc66a20f3542d901bf0da535c
index :  8 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 8 previous_hash :  dc3bd4fb62dfb15ad82e44b3768e4bc03a2085efc66a20f3542d901bf0da535c hash 5ac36c5edca409f8d3fe1d7c6323cb6488542d0dfb80390b8211992af9e278dc
index :  9 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 9 previous_hash :  5ac36c5edca409f8d3fe1d7c6323cb6488542d0dfb80390b8211992af9e278dc hash df60da5103bb153495e36d26c5fe101ecc7f445a001ca0ec5010ac1e0ca70bf5
index :  10 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 10 previous_hash :  df60da5103bb153495e36d26c5fe101ecc7f445a001ca0ec5010ac1e0ca70bf5 hash 079808737914421f6fbeaaf20764a23fd984eb1b5384c0d64b127bf9b36b69d8
index :  11 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 11 previous_hash :  079808737914421f6fbeaaf20764a23fd984eb1b5384c0d64b127bf9b36b69d8 hash 38e6a98821aa193e9b24d009fdddadab4565388ef93b4bfbf25d3ddbb6e32623
index :  12 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 12 previous_hash :  38e6a98821aa193e9b24d009fdddadab4565388ef93b4bfbf25d3ddbb6e32623 hash f668b9c2521bfb9f4562557501914c6dcbf7dad2fa84c27437be72536c763023
index :  13 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 13 previous_hash :  f668b9c2521bfb9f4562557501914c6dcbf7dad2fa84c27437be72536c763023 hash 48dc2d11c14ad8dbcdc11908185e435162da6f0f653d52bbec3c92b8471d1660
index :  14 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 14 previous_hash :  48dc2d11c14ad8dbcdc11908185e435162da6f0f653d52bbec3c92b8471d1660 hash e1745d4dd8344bc8bd01aefbf59e2a347b0bd9a743bd5e2331c4707763111862
index :  15 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 15 previous_hash :  e1745d4dd8344bc8bd01aefbf59e2a347b0bd9a743bd5e2331c4707763111862 hash fcd3d0e8fd8eb2b90ec2a913085a32de9978cc4c8eb9365dd6fc98f7b6105967
index :  16 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 16 previous_hash :  fcd3d0e8fd8eb2b90ec2a913085a32de9978cc4c8eb9365dd6fc98f7b6105967 hash c545d471f6fc9fd388868b6d0cfdac607df6348f497a907874e71139d91126e9
index :  17 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 17 previous_hash :  c545d471f6fc9fd388868b6d0cfdac607df6348f497a907874e71139d91126e9 hash 4cae02f8716133366633d2ddb3a9bc87b13cee2898eb650f2a0c21f7e550ddb5
index :  18 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 18 previous_hash :  4cae02f8716133366633d2ddb3a9bc87b13cee2898eb650f2a0c21f7e550ddb5 hash e4aa549a98cf6412a4eea651849ef76165dd2bd5d9fee44ac394a58088d6a066
index :  19 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 19 previous_hash :  e4aa549a98cf6412a4eea651849ef76165dd2bd5d9fee44ac394a58088d6a066 hash 1f21c685f6aec8e4e3c5d985873fd00c57241612c7b12f9283b5324113c8b20b
index :  20 timestamp :  2019-01-17T06:14:00.735Z data :  Hey! I'm block 20 previous_hash :  1f21c685f6aec8e4e3c5d985873fd00c57241612c7b12f9283b5324113c8b20b hash a780596a78f9bf8570903f65c86bc88fc11dfc9c717379f5694953ce1209d637
root@tkpark-VirtualBox:~/project/myapp/routes#
 

 

 

 

 

 

 

 

 

 

 

 

 

블로그 이미지

iesay