您当前的位置: 首页 >  区块链
  • 0浏览

    0关注

    1477博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

区块链 solidity 例子 smallbank

软件工程小施同学 发布时间:2021-05-07 09:50:28 ,浏览量:0

pragma solidity ^0.4.0;

contract SmallBank {
    
    //uint constant MAX_ACCOUNT = 10000;
    //uint constant BALANCE = 10000;
    //bytes20 constant accountTab = "account";
    //bytes20 constant savingTab = "saving";
    //bytes20 constant checkingTab = "checking";
    
    // 活期储蓄账户
    mapping(string=>uint) savingStore;
    // 支票账户
    mapping(string=>uint) checkingStore;

    // 将支票账户并到储蓄账户
    function almagate(string arg0, string arg1) public {
       uint bal1 = savingStore[arg0];
       uint bal2 = checkingStore[arg1];
       
       checkingStore[arg0] = 0;
       savingStore[arg1] = bal1 + bal2;
    }

    // 得到账户总余额
    function getBalance(string arg0) public constant returns (uint balance) {
        uint bal1 = savingStore[arg0];
        uint bal2 = checkingStore[arg0];
        
        balance = bal1 + bal2;
        return balance;
    }
    
    // 更新支票账户余额
    function updateBalance(string arg0, uint arg1) public {
        uint bal1 = checkingStore[arg0];
        uint bal2 = arg1;
        
        checkingStore[arg0] = bal1 + bal2;
    }
    
    // 更新储蓄账户余额
    function updateSaving(string arg0, uint arg1) public {
        uint bal1 = savingStore[arg0];
        uint bal2 = arg1;
        
        savingStore[arg0] = bal1 + bal2;
    }
    // arg0向arg1支付arg2元
    function sendPayment(string arg0, string arg1, uint arg2) public {
        uint bal1 = checkingStore[arg0];
        uint bal2 = checkingStore[arg1];
        uint amount = arg2;
        
        bal1 -= amount;
        bal2 += amount;
        
        checkingStore[arg0] = bal1;
        checkingStore[arg1] = bal2;
    }
    // 写支票
    function writeCheck(string arg0, uint arg1) public {
        uint bal1 = checkingStore[arg0];
        uint bal2 = savingStore[arg0];
        uint amount = arg1;
        
        if (amount < bal1 + bal2) {
            checkingStore[arg0] = bal1 - amount - 1;
        } 
        else {
            checkingStore[arg0] = bal1 - amount;
        }
    }
}

关注
打赏
1665320866
查看更多评论
立即登录/注册

微信扫码登录

0.0441s