1. add createRepo function

2. add selectRepoBasicInfo
3. add selectUserAllBalance
4. add selectUserBalance
This commit is contained in:
sulenn 2021-04-16 10:22:29 +08:00
parent a1aff7d2dd
commit 2e87e8fb42
54 changed files with 16809 additions and 319 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.vscode
__debug_bin
sdk.publickey
node.key
node.crt

View File

@ -0,0 +1 @@
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string","name":"token_name","type":"string"},{"internalType":"string","name":"owner","type":"string"},{"internalType":"uint256","name":"total_supply","type":"uint256"},{"internalType":"string[]","name":"username","type":"string[]"},{"internalType":"uint256[]","name":"balance","type":"uint256[]"}],"name":"createRepo","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"username","type":"string"}],"name":"selectUserAllBalance","outputs":[{"internalType":"string[]","name":"","type":"string[]"},{"internalType":"string[]","name":"","type":"string[]"},{"internalType":"int256[]","name":"","type":"int256[]"}],"stateMutability":"view","type":"function"}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

16
ca.crt
View File

@ -1,12 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIBvTCCAWSgAwIBAgIUDhho+KO+NiVPDbZ1qW0k2JuWrSAwCgYIKoZIzj0EAwIw
MIIBvjCCAWSgAwIBAgIUAguKbcVr58FSgPHWPE2zcvQqSgUwCgYIKoZIzj0EAwIw
NTEOMAwGA1UEAwwFY2hhaW4xEzARBgNVBAoMCmZpc2NvLWJjb3MxDjAMBgNVBAsM
BWNoYWluMCAXDTIxMDQxMzAyMzEwN1oYDzIxMjEwMzIwMDIzMTA3WjA1MQ4wDAYD
BWNoYWluMCAXDTIxMDQxNjAwNTI0NloYDzIxMjEwMzIzMDA1MjQ2WjA1MQ4wDAYD
VQQDDAVjaGFpbjETMBEGA1UECgwKZmlzY28tYmNvczEOMAwGA1UECwwFY2hhaW4w
VjAQBgcqhkjOPQIBBgUrgQQACgNCAAT1g2PYfplTEEgsssKEbqm1k4ugVYztSxEI
yoHC0vssQ+i1D4N6X2Gtp4BmMvNC1fnUAkpOqtdmOGxyVGDfOMOUo1MwUTAdBgNV
HQ4EFgQUKIIfjS6rQUmR+Je8SN1NBCEJA0AwHwYDVR0jBBgwFoAUKIIfjS6rQUmR
+Je8SN1NBCEJA0AwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNHADBEAiBk
R8l1Tmhbx840R0lS45drffXzsKz78n20QleYMenPdgIgQ0ssRyWL8MpZXM6orEwc
3PueajQ3tgkkxDwngCH5bdY=
VjAQBgcqhkjOPQIBBgUrgQQACgNCAATBgqh3oOWZnu6q30RFla5D5mUgzBxNvH5n
B1r0tHeBip5sRf0c6bi0sUyTwmIIeZw1icxOdMCYc7FdPEoH+To8o1MwUTAdBgNV
HQ4EFgQUw/DeoMeA72HHjWaHxx1DrRGSPeMwHwYDVR0jBBgwFoAUw/DeoMeA72HH
jWaHxx1DrRGSPeMwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNIADBFAiEA
liP0SdyqcI419xzXPK7dN75eTihUX9FfUqiAhxDp2DwCIGnR1SKLt3wBcSanxFfP
aD/Caxx6mnAqQ46t6PtedbDV
-----END CERTIFICATE-----

View File

@ -1 +0,0 @@
[{"constant":false,"inputs":[{"name":"token_name","type":"string"},{"name":"owner","type":"string"},{"name":"total_supply","type":"int256"}],"name":"insert","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@ import (
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
table "github.com/sulenn/trustie-fisco-bcos/contract" // import tabletest
table "github.com/sulenn/trustie-fisco-bcos/contract/opensource" // import tabletest
)
func main() {

View File

@ -9,7 +9,7 @@ import (
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
"github.com/ethereum/go-ethereum/common"
table "github.com/sulenn/trustie-fisco-bcos/contract"
table "github.com/sulenn/trustie-fisco-bcos/contract/opensource"
)
func main() {
@ -25,7 +25,7 @@ func main() {
}
// load the contract
contractAddress := common.HexToAddress("0xcb465127073489235bBB8cF6995172a7c7420b3F") // 0x9526BDd51d7F346ec2B48192f25a800825A8dBF3
contractAddress := common.HexToAddress("0xcb465127073489235bBB8cF6995172a7c7420b3F")
instance, err := table.NewOpenSource(contractAddress, client)
if err != nil {
log.Fatal(err)
@ -36,7 +36,9 @@ func main() {
token_name := "repo1"
owner := "sulenn"
total_supply := big.NewInt(1000000)
tx, receipt, err := tabletestSession.Insert(token_name, owner, total_supply) // call Insert API
username := []string{"qiubing"}
balance := []*big.Int{big.NewInt(100000)}
tx, receipt, err := tabletestSession.Insert(token_name, owner, total_supply, username, balance) // call Insert API
if err != nil {
log.Fatal(err)
}

8
contract/flag.go Normal file
View File

@ -0,0 +1,8 @@
package contract
var (
RepoExisted int64 = -1001 // 在合约中创建项目时,项目已存在
BalanceOverFlow int64 = -1002 // 在合约中创建项目时预分配的用户Token累积值大于项目总Token
ContractAddress string = "0xcb465127073489235bBB8cF6995172a7c7420b3F"
)

View File

@ -1,37 +0,0 @@
pragma solidity>=0.4.24 <=0.7.0;
pragma experimental ABIEncoderV2;
import "./Table.sol";
contract OpenSource {
TableFactory tableFactory;
string constant REPO_TABLE = "repo";
string constant USER_TABLE = "user";
constructor() public {
tableFactory = TableFactory(0x1001); //The fixed address is 0x1001 for TableFactory
// the parameters of createTable are tableName,keyField,"vlaueFiled1,vlaueFiled2,vlaueFiled3,..."
tableFactory.createTable(REPO_TABLE, "token_name", "owner,total_supply");
tableFactory.createTable(USER_TABLE, "user", "token_name,balance");
}
//insert records
function insert(string memory token_name, string memory owner, int256 total_supply)
// function insert(string memory token_name, string memory owner, int256 total_supply, string memory user, int256 balance)
public
returns (int256)
{
Table repo_table = tableFactory.openTable(REPO_TABLE);
Table user_table = tableFactory.openTable(USER_TABLE);
Entry repo_entry = repo_table.newEntry();
repo_entry.set("token_name", token_name);
repo_entry.set("owner", owner);
repo_entry.set("total_supply", total_supply);
int256 count = repo_table.insert(token_name, repo_entry);
// emit InsertResult(count);
return count;
}
}

View File

@ -0,0 +1 @@
[{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"name":"GT","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"name":"NE","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"int256"}],"name":"limit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"name":"NE","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"name":"GE","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"int256"},{"name":"","type":"int256"}],"name":"limit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"name":"LE","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"name":"LT","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"name":"EQ","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"name":"EQ","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

View File

@ -0,0 +1 @@
608060405234801561001057600080fd5b50610570806100206000396000f3006080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806308ad6333146100a95780632783acf51461011c5780632e0d738a146101cb57806339aef024146101f857806342f8dd311461026b5780637ec1cc65146102de578063b6f2385714610315578063c31c9b6514610388578063cd30a1d1146103fb578063e44594b9146104aa575b600080fd5b3480156100b557600080fd5b5061011a600480360381019080803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192908035906020019092919050505061051d565b005b34801561012857600080fd5b506101c9600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610521565b005b3480156101d757600080fd5b506101f660048036038101908080359060200190929190505050610525565b005b34801561020457600080fd5b50610269600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929080359060200190929190505050610528565b005b34801561027757600080fd5b506102dc600480360381019080803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192908035906020019092919050505061052c565b005b3480156102ea57600080fd5b506103136004803603810190808035906020019092919080359060200190929190505050610530565b005b34801561032157600080fd5b50610386600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929080359060200190929190505050610534565b005b34801561039457600080fd5b506103f9600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929080359060200190929190505050610538565b005b34801561040757600080fd5b506104a8600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061053c565b005b3480156104b657600080fd5b5061051b600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929080359060200190929190505050610540565b005b5050565b5050565b50565b5050565b5050565b5050565b5050565b5050565b5050565b50505600a165627a7a7230582090710b84578cde58cb9eaefd0c7fcec7e2d7a870478771ddda19a640f950d09a0029

View File

@ -0,0 +1 @@
[{"constant":true,"inputs":[{"name":"","type":"int256"}],"name":"get","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"size","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"}]

View File

@ -0,0 +1 @@
608060405234801561001057600080fd5b50610118806100206000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063846719e014604e578063949d225d1460b8575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060e0565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801560c357600080fd5b5060ca60e7565b6040518082815260200191505060405180910390f35b6000919050565b6000905600a165627a7a723058204e5bbf9854a6bc3833fb75183dcee5b11e6303a2d5d443d48cedb3090017928b0029

View File

@ -0,0 +1 @@
[{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"getBytes32","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"getUInt","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"getString","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"address"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"getAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"getBytes64","outputs":[{"name":"","type":"bytes1[64]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"getInt","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"}]

View File

@ -0,0 +1 @@
608060405234801561001057600080fd5b50610706806100206000396000f3006080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806327314f79146100a95780632ef8ba741461012e5780633536046a146101a15780638a42ebe91461021e5780639c981fcb14610291578063a815ff1514610373578063bf40fac1146103fc578063d52decd4146104a5578063e942b5161461054a578063fda69fae146105f9575b600080fd5b3480156100b557600080fd5b50610110600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610676565b60405180826000191660001916815260200191505060405180910390f35b34801561013a57600080fd5b5061019f600480360381019080803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192908035906020019092919050505061067d565b005b3480156101ad57600080fd5b50610208600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610681565b6040518082815260200191505060405180910390f35b34801561022a57600080fd5b5061028f600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929080359060200190929190505050610688565b005b34801561029d57600080fd5b506102f8600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061068c565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561033857808201518184015260208101905061031d565b50505050905090810190601f1680156103655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561037f57600080fd5b506103fa600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610693565b005b34801561040857600080fd5b50610463600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610697565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156104b157600080fd5b5061050c600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061069e565b6040518082604060200280838360005b8381101561053757808201518184015260208101905061051c565b5050505090500191505060405180910390f35b34801561055657600080fd5b506105f7600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506106ab565b005b34801561060557600080fd5b50610660600480360381019080803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506106af565b6040518082815260200191505060405180910390f35b6000919050565b5050565b6000919050565b5050565b6060919050565b5050565b6000919050565b6106a66106b6565b919050565b5050565b6000919050565b610800604051908101604052806040906020820280388339808201915050905050905600a165627a7a723058202cc4c32a72c125f4237c02f14ceba75a2f552e41a2822f92aaf71d7dfc2999ff0029

View File

@ -0,0 +1 @@
[{"constant":true,"inputs":[],"name":"newEntry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"get","outputs":[{"name":"","type":"bool"},{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"address"}],"name":"set","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]

View File

@ -0,0 +1 @@
608060405234801561001057600080fd5b50610245806100206000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806313db93461461005c578063693ec85e146100b3578063a815ff1514610167575b600080fd5b34801561006857600080fd5b50610071610204565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100bf57600080fd5b5061011a600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610209565b60405180831515151581526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390f35b34801561017357600080fd5b506101ee600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610211565b6040518082815260200191505060405180910390f35b600090565b600080915091565b6000929150505600a165627a7a723058200e0db23da1cb08d947b6633a5c57207aab81719b1ca016efbf6c485d32d4ede00029

View File

@ -0,0 +1 @@
[{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"}],"name":"createTable","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"openTable","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]

View File

@ -0,0 +1 @@
608060405234801561001057600080fd5b5061023f806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806356004b6a14610051578063f23f63c91461015a575b600080fd5b34801561005d57600080fd5b50610144600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610203565b6040518082815260200191505060405180910390f35b34801561016657600080fd5b506101c1600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061020c565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60009392505050565b60009190505600a165627a7a72305820620c3539295804f9b2cdeb63bf347755cf7b25f807c039bde297e96301b6c48f0029

View File

@ -0,0 +1 @@
[{"constant":true,"inputs":[{"name":"username","type":"string"},{"name":"token_name","type":"string"}],"name":"selectUserBalance","outputs":[{"name":"","type":"string[]"},{"name":"","type":"string[]"},{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"username","type":"string"}],"name":"selectUserAllBalance","outputs":[{"name":"","type":"string[]"},{"name":"","type":"string[]"},{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"token_name","type":"string"},{"name":"owner","type":"string"},{"name":"total_supply","type":"uint256"},{"name":"cur_supply","type":"uint256"},{"name":"username","type":"string[]"},{"name":"balance","type":"uint256[]"}],"name":"createRepo","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"token_name","type":"string"}],"name":"selectRepoBasicInfo","outputs":[{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"int256"},{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
608060405234801561001057600080fd5b50610442806100206000396000f300608060405260043610610078576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806313db93461461007d57806328bb2117146100d457806331afac36146101715780637857d7c91461020e578063bf2b70a114610265578063e8434e3914610322575b600080fd5b34801561008957600080fd5b506100926103eb565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100e057600080fd5b5061015b600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103f0565b6040518082815260200191505060405180910390f35b34801561017d57600080fd5b506101f8600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103f8565b6040518082815260200191505060405180910390f35b34801561021a57600080fd5b50610223610400565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561027157600080fd5b5061030c600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610405565b6040518082815260200191505060405180910390f35b34801561032e57600080fd5b506103a9600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061040e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600090565b600092915050565b600092915050565b600090565b60009392505050565b6000929150505600a165627a7a72305820347636edbe12a60ed1c5446a5d5c620a59cdf26baad63c597a75cdca62d66f570029
608060405234801561001057600080fd5b50610442806100206000396000f300608060405260043610610078576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806313db93461461007d57806328bb2117146100d457806331afac36146101715780637857d7c91461020e578063bf2b70a114610265578063e8434e3914610322575b600080fd5b34801561008957600080fd5b506100926103eb565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100e057600080fd5b5061015b600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103f0565b6040518082815260200191505060405180910390f35b34801561017d57600080fd5b506101f8600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103f8565b6040518082815260200191505060405180910390f35b34801561021a57600080fd5b50610223610400565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561027157600080fd5b5061030c600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610405565b6040518082815260200191505060405180910390f35b34801561032e57600080fd5b506103a9600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061040e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600090565b600092915050565b600092915050565b600090565b60009392505050565b6000929150505600a165627a7a7230582027f3a06c6b7fd8fac14e10384a94f0ded8d1cdf1979b6871804cc92bbf9706500029

View File

@ -0,0 +1 @@
[{"constant":false,"inputs":[{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"}],"name":"createTable","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"string"}],"name":"openTable","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]

View File

@ -0,0 +1 @@
608060405234801561001057600080fd5b5061023f806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806356004b6a14610051578063f23f63c91461015a575b600080fd5b34801561005d57600080fd5b50610144600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610203565b6040518082815260200191505060405180910390f35b34801561016657600080fd5b506101c1600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061020c565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60009392505050565b60009190505600a165627a7a7230582065aa33e52fdda250c550f17e927edad93ccab126e428f56915db73e4c84e8e670029

View File

@ -0,0 +1,161 @@
pragma solidity>=0.4.24 <=0.7.0;
pragma experimental ABIEncoderV2;
import "./Table.sol";
contract OpenSource {
TableFactory tableFactory;
string constant REPO_TABLE = "repo";
string constant USER_TABLE = "user";
constructor() public {
tableFactory = TableFactory(0x1001); //The fixed address is 0x1001 for TableFactory
// the parameters of createTable are tableName,keyField,"vlaueFiled1,vlaueFiled2,vlaueFiled3,..."
tableFactory.createTable(REPO_TABLE, "token_name", "owner,total_supply,cur_supply");
tableFactory.createTable(USER_TABLE, "user", "token_name,balance");
}
// create repo
function createRepo(string memory token_name, string memory owner, uint256 total_supply, uint256 cur_supply, string[] memory username, uint256[] memory balance)
public
returns (int256)
{
if (judgeReposExisted(token_name) == true) {
return -1001;
}
if (total_supply < cur_supply) {
return -1002;
}
Table repo_table = tableFactory.openTable(REPO_TABLE);
Table user_table = tableFactory.openTable(USER_TABLE);
Entry repo_entry = repo_table.newEntry();
repo_entry.set("token_name", token_name);
repo_entry.set("owner", owner);
repo_entry.set("total_supply", total_supply);
repo_entry.set("cur_supply", cur_supply);
int256 count = repo_table.insert(token_name, repo_entry);
if (count != 1) {
return count;
}
Entry user_entry = user_table.newEntry();
uint256 i = 0;
for (i = 0; i < balance.length; ++i) {
user_entry = user_table.newEntry();
user_entry.set("user", username[i]);
user_entry.set("token_name", token_name);
user_entry.set("balance", balance[i]);
count = user_table.insert(username[i], user_entry);
if (count != 1) {
return count;
}
}
// emit InsertResult(count);
return count;
}
function selectRepoBasicInfo(string memory token_name)
public
view
returns (string memory, string memory, int256, int256)
{
Table repo_table = tableFactory.openTable(REPO_TABLE);
Condition condition = repo_table.newCondition();
Entries entries = repo_table.select(token_name, condition);
Entry entry = entries.get(0);
return (entry.getString("token_Name"), entry.getString("owner"), entry.getInt("total_supply"), entry.getInt("cur_supply"));
}
// select user all balance
function selectUserAllBalance(string memory username)
public
view
returns (string[] memory, string[] memory, uint256[] memory)
{
Table user_table = tableFactory.openTable(USER_TABLE);
Condition condition = user_table.newCondition();
Entries entries = user_table.select(username, condition);
string[] memory username_list = new string[](uint256(entries.size()));
string[] memory token_name_list = new string[](uint256(entries.size()));
uint256[] memory balance_list = new uint256[](uint256(entries.size()));
for (int256 i = 0; i < entries.size(); ++i) {
Entry entry = entries.get(i);
username_list[uint256(i)] = entry.getString("user");
token_name_list[uint256(i)] = entry.getString("token_name");
balance_list[uint256(i)] = entry.getUInt("balance");
}
return (username_list, token_name_list, balance_list);
}
// select single user balance
function selectUserBalance(string memory username, string memory token_name)
public
view
returns (string[] memory, string[] memory, uint256[] memory)
{
Table user_table = tableFactory.openTable(USER_TABLE);
Condition condition = user_table.newCondition();
condition.EQ("token_name", token_name);
Entries entries = user_table.select(username, condition);
string[] memory username_list = new string[](uint256(entries.size()));
string[] memory token_name_list = new string[](uint256(entries.size()));
uint256[] memory balance_list = new uint256[](uint256(entries.size()));
for (int256 i = 0; i < entries.size(); ++i) {
Entry entry = entries.get(i);
username_list[uint256(i)] = entry.getString("user");
token_name_list[uint256(i)] = entry.getString("token_name");
balance_list[uint256(i)] = entry.getUInt("balance");
}
return (username_list, token_name_list, balance_list);
}
// // add user balance
// function addUserBalance(string memory username, string memory token_name)
// public
// view
// returns (string[] memory, string[] memory, uint256[] memory)
// {
// Table user_table = tableFactory.openTable(USER_TABLE);
// Condition condition = user_table.newCondition();
// condition.EQ("token_name", token_name);
// Entries entries = user_table.select(username, condition);
// string[] memory username_list = new string[](uint256(entries.size()));
// string[] memory token_name_list = new string[](uint256(entries.size()));
// uint256[] memory balance_list = new uint256[](uint256(entries.size()));
// for (int256 i = 0; i < entries.size(); ++i) {
// Entry entry = entries.get(i);
// username_list[uint256(i)] = entry.getString("user");
// token_name_list[uint256(i)] = entry.getString("token_name");
// balance_list[uint256(i)] = entry.getUInt("balance");
// }
// return (username_list, token_name_list, balance_list);
// }
function judgeReposExisted(string memory token_name) private returns (bool) {
Table repo_table = tableFactory.openTable(REPO_TABLE);
Condition condition = repo_table.newCondition();
Entries entries = repo_table.select(token_name, condition);
if (entries.size() > 0) {
return true;
}
return false;
}
}

2
go.mod
View File

@ -3,6 +3,8 @@ module github.com/sulenn/trustie-fisco-bcos
go 1.15
require (
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
gitea.com/macaron/macaron v1.5.0
github.com/FISCO-BCOS/go-sdk v0.11.0
github.com/ethereum/go-ethereum v1.10.2
)

19
go.sum
View File

@ -19,6 +19,14 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b h1:vXt85uYV17KURaUlhU7v4GbCShkqRZDSfo0TkC0YCjQ=
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b/go.mod h1:Cxadig6POWpPYYSfg23E7jo35Yf0yvsdC1lifoKWmPo=
gitea.com/macaron/inject v0.0.0-20190803172902-8375ba841591/go.mod h1:h6E4kLao1Yko6DOU6QDnQPcuoNzvbZqzj2mtPcEn1aM=
gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a h1:aOKEXkDTnh4euoH0so/THLXeHtQuqHmDPb1xEk6Ehok=
gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a/go.mod h1:h6E4kLao1Yko6DOU6QDnQPcuoNzvbZqzj2mtPcEn1aM=
gitea.com/macaron/macaron v1.3.3-0.20190821202302-9646c0587edb/go.mod h1:0coI+mSPSwbsyAbOuFllVS38awuk9mevhLD52l50Gjs=
gitea.com/macaron/macaron v1.5.0 h1:TvWEcHw1/zaHlo0GTuKEukLh3A99+QsU2mjBrXLXjVQ=
gitea.com/macaron/macaron v1.5.0/go.mod h1:P7hfDbQjcW22lkYkXlxdRIfWOXxH2+K4EogN4Q0UlLY=
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc=
github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4=
@ -222,6 +230,7 @@ github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@ -288,6 +297,7 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jsternberg/zap-logfmt v1.0.0/go.mod h1:uvPs/4X51zdkcm5jXl5SYoN+4RK21K8mysFmDaM/h+o=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
@ -429,6 +439,10 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
@ -470,6 +484,9 @@ github.com/tjfoc/gmsm v1.3.0/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM=
github.com/unknwon/com v1.0.1 h1:3d1LTxD+Lnf3soQiD4Cp/0BRB+Rsa/+RTvz8GMMzIXs=
github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
@ -496,6 +513,7 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190909091759-094676da4a83/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@ -714,6 +732,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/jcmturner/aescts.v1 v1.0.1/go.mod h1:nsR8qBOg+OucoIW+WMhB3GspUQXq9XorLnQb9XtvcOo=

12
main.go Normal file
View File

@ -0,0 +1,12 @@
package main
import (
"github.com/sulenn/trustie-fisco-bcos/modules/os"
"github.com/sulenn/trustie-fisco-bcos/routers/routes"
)
func main() {
m := routes.NewMacaron()
os.SetListeningPort("8000") // 设置监听端口
m.Run() // 如果存在环境变量 port则读取。否则默认监听 4000
}

View File

@ -0,0 +1,27 @@
package format
import (
"encoding/json"
"errors"
)
type ChaincodeArgs struct {
Func string `json:"Func"` // 调用链码时指定的函数名
Args []string `json:"Args"` // 调用链码函数时传入的参数
}
func ArgsJson(function string, args ...string) (*string, error) { //链码参数转字符串
if len(function) == 0 {
return nil, errors.New("function name is not nil")
}
chaincodeArgs := &ChaincodeArgs{
Func: function,
Args: args,
}
chaincodeArgsToJsonBytes, err := json.Marshal(chaincodeArgs)
if err != nil {
return nil, err
}
chaincodeArgsToJsonString := string(chaincodeArgsToJsonBytes)
return &chaincodeArgsToJsonString, nil
}

View File

@ -0,0 +1,15 @@
package format
import (
"testing"
)
func Test_ArgsJson(T *testing.T) {
chaincodeArgsToJsonString, err := ArgsJson("transfer", "nudt1", "sulenn", "qiubing", "10")
if err != nil {
T.Error(err)
}
if *chaincodeArgsToJsonString != "{\"Func\":\"transfer\",\"Args\":[\"nudt1\",\"sulenn\",\"qiubing\",\"10\"]}" {
T.Error(*chaincodeArgsToJsonString)
}
}

23
modules/os/common.go Normal file
View File

@ -0,0 +1,23 @@
package os
import (
"errors"
"os"
"strconv"
)
// SetListeningPort is to set listening port
func SetListeningPort(port string) error { // 设置服务监听端口
if len(port) == 0 {
return errors.New("port is nil")
}
value, err := strconv.Atoi(port)
if err != nil {
return err
}
if value < 1 || value > 65535 { // port 越界
return errors.New("out of port")
}
os.Setenv("PORT", port) // 设置端口
return nil
}

View File

@ -0,0 +1,10 @@
package structs
type InstallChaincodeOption struct {
Orgname string `json:"orgnization_name"`
Peers []string `json:"peers"`
ChaincodeName string `json:"chaincode_name"`
ChaincodePath string `json:"chaincode_path"`
ChaincodeVersion string `json:"chaincode_version"`
ChaincodeType string `json:"chaincode_type"` // 链码所用语言
}

View File

@ -0,0 +1,17 @@
package structs
type CreateChannelOption struct {
CommonOption
ChannelConfigPath string `json:"channel_config_path"`
}
type JoinChannelOption struct {
CommonOption
Peers []string `json:"peers"`
}
// 公共属性
type CommonOption struct {
ChannelName string `json:"channel_name" binding:"Required"`
Orgname string `json:"orgnization_name"`
}

View File

@ -0,0 +1,25 @@
package structs
type InstantiateChaincodeOption struct {
CommonOption
Peers []string `json:"peers"`
ChaincodeName string `json:"chaincode_name"`
ChaincodeVersion string `json:"chaincode_version"`
ChaincodeType string `json:"chaincode_type"` // 链码所用语言
}
type InvokeChaincodeOption struct {
CommonOption
Peers []string `json:"peers"`
ChaincodeName string `json:"chaincode_name"`
FunctionName string `json:"function_name"` // 调用链码中的方法名
Args []string `json:"args"` // 调用链码时传入的参数
}
type QueryChaincodeOption struct {
CommonOption
ChaincodeName string `json:"chaincode_name"`
Peer string `json:"peer"`
FunctionName string `json:"function_name"` // 调用链码中的方法名
Args string `json:"args"` // 调用链码时传入的参数
}

48
modules/structs/repo.go Normal file
View File

@ -0,0 +1,48 @@
package structs
// CreateRepoOption is options when to create a repository
type CreateRepoOption struct {
Owner string `json:"username" binding:"Required"` // 创始人
TotalSupply uint64 `json:"total_supply" binding:"Required"` // 项目初始金额
TokenName string `json:"token_name" binding:"Required"` // 项目名
TokenBalance [][]interface{} `json:"token_balance"` // 用户初始Token分配
}
type Repo struct {
Owner string `json:"username"` // 创始人
TokenName string `json:"token_name"` // 项目代号(默认等同于项目名)
TotalSupply uint64 `json:"total_supply"` // 项目初始金额
CurSupply uint64 `json:"cur_supply"` // 项目当前金额
}
// TransferTokenOption is options when to transfer amount from one person to another
type TransferTokenOption struct {
TokenSymbol string `json:"reponame" binding:"Required"` // 项目名
From string `json:"payer" binding:"Required"` // 付款人
To string `json:"payee" binding:"Required"` // 收款人
Amount uint64 `json:"amount" binding:"Required"` // 金额
}
// AddTokenOption is options when user add amount
type AddTokenOption struct {
TokenSymbol string `json:"reponame" binding:"Required"` // 项目名
Username string `json:"username" binding:"Required"` // 用户名
Amount uint64 `json:"amount" binding:"Required"` // 金额
}
// MinusTokenOption is options when user minus amount
type MinusTokenOption struct {
TokenSymbol string `json:"reponame" binding:"Required"` // 项目名
Username string `json:"username" binding:"Required"` // 用户名
Amount uint64 `json:"amount" binding:"Required"` // 金额
}
// // UserBalance represents a user's balance
// type UserBalance struct {
// Username string `json:"username" binding:"Required"` // 用户名
// TokenSymbol string `json:"reponame" binding:"Required"` // 项目名
// Balance uint64 `json:"balance"` // 用户余额
// }
// // UserBalanceList represents all user's balance list in repository
// type UserBalanceList []*UserBalance

View File

@ -0,0 +1,11 @@
package structs
// UploadCommitOption is to upload commit info to blockchain
type UploadCommitOption struct {
Sha string `json:"sha" binding:"Required"` // sha 值
Branch string `json:"branch" binding:"Required"` // 分支
Ownername string `json:"ownername" binding:"Required"` // 项目创始人
Reponame string `json:"reponame" binding:"Required"` // 项目名
Username string `json:"username" binding:"Required"` // 用户名
ModificationLines int `json:"modification_lines" binding:"Required"` //修改行数
}

View File

@ -0,0 +1,16 @@
package structs
type Response struct {
Status uint16 `json:"status"`
Message string `json:"message"`
}
var (
ResRepoSucc = &Response{Status: 0, Message: "create repo successfully!"} // create repo successfully!
ResRepoExisted = &Response{Status: 1, Message: "repo existed!"} // repo existed!
ResRepoBalanceOverFlow = &Response{Status: 1, Message: "username balance overflow when create repo!"} // username balance overflow when create repo!
ResRepoUnsucc = &Response{Status: 2, Message: "create repo unsuccessfully!"} // create repo unsuccessfully!
TypeTransferErr = &Response{Status: 10, Message: "type transfer error!"} // type transfer error!
StringEmpty = &Response{Status: 10, Message: "string empty!"} // string empty!
)

18
modules/structs/user.go Normal file
View File

@ -0,0 +1,18 @@
package structs
type User struct {
Username string `json:"username" binding:"Required"`
TokenName string `json:"token_name"`
}
type UserBalance struct {
User
Balance uint64 `json:"balance"`
}
type UserBalanceList []*UserBalance
// type CreateUserOption struct {
// Username string `json:"username" binding:"Required"`
// Orgname string `json:"orgnization_name" binding:"Required"`
// }

View File

@ -0,0 +1,18 @@
package chaincode
import (
"gitea.com/macaron/macaron"
api "github.com/sulenn/trustie-fisco-bcos/modules/structs"
)
func Install(ctx *macaron.Context, opt api.InstallChaincodeOption) {
var installChaincodeOption = &api.InstallChaincodeOption{
Orgname: opt.Orgname,
Peers: opt.Peers,
ChaincodeName: opt.ChaincodeName,
ChaincodePath: opt.ChaincodePath,
ChaincodeVersion: opt.ChaincodeVersion,
ChaincodeType: opt.ChaincodeType,
}
ctx.JSON(200, installChaincodeOption)
}

View File

@ -0,0 +1,25 @@
package channel
import (
api "github.com/sulenn/trustie-fisco-bcos/modules/structs"
"gitea.com/macaron/macaron"
)
// 创建 channel
func Create(ctx *macaron.Context, opt api.CreateChannelOption) {
var channel = &api.CreateChannelOption{
CommonOption: api.CommonOption{ChannelName: opt.ChannelName, Orgname: opt.Orgname},
ChannelConfigPath: opt.ChannelConfigPath,
}
ctx.JSON(200, channel)
}
// 节点加入通道
func Join(ctx *macaron.Context, opt api.JoinChannelOption) {
var joinChannelOption = &api.JoinChannelOption{
CommonOption: api.CommonOption{ChannelName: opt.ChannelName, Orgname: opt.Orgname},
Peers: opt.Peers,
}
ctx.JSON(200, joinChannelOption)
}

View File

@ -0,0 +1,42 @@
package channel
import (
"gitea.com/macaron/macaron"
api "github.com/sulenn/trustie-fisco-bcos/modules/structs"
)
// 在通道中实例化链码
func InstantiateChaincode(ctx *macaron.Context, opt api.InstantiateChaincodeOption) {
var instantiateChaincodeOption = &api.InstantiateChaincodeOption{
CommonOption: api.CommonOption{ChannelName: opt.ChannelName, Orgname: opt.Orgname},
Peers: opt.Peers,
ChaincodeName: opt.ChaincodeName,
ChaincodeVersion: opt.ChaincodeVersion,
ChaincodeType: opt.ChaincodeType,
}
ctx.JSON(200, instantiateChaincodeOption)
}
// 调用链码,完成交易
func InvokeChaincode(ctx *macaron.Context, opt api.InvokeChaincodeOption) {
var invokeChaincodeOption = &api.InvokeChaincodeOption{
CommonOption: api.CommonOption{ChannelName: opt.ChannelName, Orgname: opt.Orgname},
Peers: opt.Peers,
ChaincodeName: opt.ChaincodeName,
FunctionName: opt.FunctionName,
Args: opt.Args,
}
ctx.JSON(200, invokeChaincodeOption)
}
// 查询链码中数据
func QueryChaincode(ctx *macaron.Context) {
var queryChaincodeOption = &api.QueryChaincodeOption{
CommonOption: api.CommonOption{ChannelName: ctx.Params(":channelName"), Orgname: ctx.Query("orgnization_name")},
ChaincodeName: ctx.Params(":chaincodeName"),
Peer: ctx.Query("peer"),
FunctionName: ctx.Query("function_name"),
Args: ctx.Query("args"),
}
ctx.JSON(200, queryChaincodeOption)
}

407
routers/repo/repo.go Normal file
View File

@ -0,0 +1,407 @@
package repo
import (
"encoding/hex"
"fmt"
"log"
"math/big"
"net/http"
"strings"
"github.com/FISCO-BCOS/go-sdk/abi"
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
"github.com/FISCO-BCOS/go-sdk/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/sulenn/trustie-fisco-bcos/contract"
"github.com/sulenn/trustie-fisco-bcos/contract/opensource"
"github.com/sulenn/trustie-fisco-bcos/modules/structs"
api "github.com/sulenn/trustie-fisco-bcos/modules/structs"
"gitea.com/macaron/macaron"
)
var ()
// Create is to create a repository in blockchain ledger
func Create(ctx *macaron.Context, opt api.CreateRepoOption, logger *log.Logger) { // 创建项目
tokenName := opt.TokenName
owner := opt.Owner
totalSupply := big.NewInt(int64(opt.TotalSupply))
token_balance := opt.TokenBalance
var usernameArr = []string{}
var balanceArr = []*big.Int{}
var curSupply int64 = 0
for i := 0; i < len(token_balance); i++ {
username, ok := token_balance[i][0].(string)
if ok != true {
ctx.JSON(http.StatusOK, structs.TypeTransferErr)
return
}
usernameArr = append(usernameArr, username)
balance, ok := token_balance[i][1].(float64)
curSupply += int64(balance)
if ok != true {
ctx.JSON(http.StatusOK, structs.TypeTransferErr)
return
}
balanceArr = append(balanceArr, big.NewInt(int64(balance)))
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
logger.Panic(err)
return
}
config := &configs[0]
client, err := client.Dial(config)
if err != nil {
logger.Panic(err)
return
}
// load the contract
contractAddress := common.HexToAddress(contract.ContractAddress)
instance, err := opensource.NewOpenSource(contractAddress, client)
if err != nil {
logger.Panic(err)
return
}
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
tx, receipt, err := openSourceSession.CreateRepo(tokenName, owner, totalSupply, big.NewInt(curSupply), usernameArr, balanceArr) // call Insert API
if err != nil {
logger.Panic(err)
return
}
logger.Printf("tx sent: %s\n", tx.Hash().Hex())
// insertedLines, err := strconv.Atoi(receipt.Output[2:])
code, err := parseOutput(opensource.OpenSourceABI, "createRepo", receipt)
if err != nil {
logger.Panic("error when transfer string to int: ", err)
}
if code.Int64() > 0 {
logger.Printf("inserted lines: %v\n", code)
ctx.JSON(http.StatusOK, structs.ResRepoSucc)
return
} else if code.Int64() == contract.RepoExisted {
logger.Printf("error code: %v, message: %v\n", code, structs.ResRepoExisted)
ctx.JSON(http.StatusOK, structs.ResRepoExisted)
return
} else if code.Int64() == contract.BalanceOverFlow {
logger.Printf("error code: %v, message: %v\n", code, structs.ResRepoBalanceOverFlow)
ctx.JSON(http.StatusOK, structs.ResRepoBalanceOverFlow)
return
}
ctx.JSON(http.StatusOK, structs.ResRepoUnsucc)
}
func QueryBasic(ctx *macaron.Context, logger *log.Logger) {
tokenName := ctx.Query("tokenname")
if tokenName == "" {
ctx.JSON(http.StatusOK, api.StringEmpty)
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
logger.Panic(err)
return
}
config := &configs[0]
client, err := client.Dial(config)
if err != nil {
logger.Panic(err)
return
}
// load the contract
contractAddress := common.HexToAddress(contract.ContractAddress)
instance, err := opensource.NewOpenSource(contractAddress, client)
if err != nil {
logger.Panic(err)
return
}
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
_, owner, totalSupply, curSupply, err := openSourceSession.SelectRepoBasicInfo(tokenName) // call Insert API
if err != nil {
logger.Panic(err)
return
}
fmt.Printf("tokenName: %v, owner: %v, totalSupply: %v, curSupply: %v \n", tokenName, owner, totalSupply, curSupply)
ctx.JSON(http.StatusOK, &structs.Repo{
TokenName: tokenName,
Owner: owner,
TotalSupply: totalSupply.Uint64(),
CurSupply: curSupply.Uint64(),
})
}
func parseOutput(abiStr, name string, receipt *types.Receipt) (*big.Int, error) {
parsed, err := abi.JSON(strings.NewReader(abiStr))
if err != nil {
fmt.Printf("parse ABI failed, err: %v", err)
}
var ret *big.Int
b, err := hex.DecodeString(receipt.Output[2:])
if err != nil {
return nil, fmt.Errorf("decode receipt.Output[2:] failed, err: %v", err)
}
err = parsed.Unpack(&ret, name, b)
if err != nil {
return nil, fmt.Errorf("unpack %v failed, err: %v", name, err)
}
return ret, nil
}
// // Transfer is to transfer amount from one person to another
// func Transfer(ctx *macaron.Context, opt api.TransferTokenOption) { // 转账
// tokenSymbol := opt.TokenSymbol
// from := opt.From
// to := opt.To
// amount := fmt.Sprintf("%v", opt.Amount)
// chainArgsToJsonString, err := format.ArgsJson("transfer", tokenSymbol, from, to, amount)
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("trasfer:%v", err))
// return
// }
// err = chaincode.InvokeOther(*chainArgsToJsonString)
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("trasfer:%v", err))
// return
// }
// userBalanceList := structs.UserBalanceList{}
// payerAmout, err := queryUserBalance(tokenSymbol, from) // 付款人余额信息
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("It is failed when query payer amount: %v", err))
// return
// }
// payer := &structs.UserBalance{
// Username: from,
// TokenSymbol: tokenSymbol,
// Balance: *payerAmout,
// }
// userBalanceList = append(userBalanceList, payer)
// payeeAmout, err := queryUserBalance(tokenSymbol, to) // 收款人余额信息
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("It is failed when query payee amount: %v", err))
// return
// }
// payee := &structs.UserBalance{
// Username: to,
// TokenSymbol: tokenSymbol,
// Balance: *payeeAmout,
// }
// userBalanceList = append(userBalanceList, payee)
// ctx.JSON(http.StatusOK, userBalanceList)
// }
// // Add is to help user add amount
// func Add(ctx *macaron.Context, opt api.AddTokenOption) { // 增加用户余额
// tokenSymbol := opt.TokenSymbol
// username := opt.Username
// amount := fmt.Sprintf("%v", opt.Amount)
// err := add(tokenSymbol, username, amount)
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("add: %v", err))
// return
// }
// userAmout, err := queryUserBalance(tokenSymbol, username) // 用户余额信息
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("It is failed when query user amount: %v", err))
// return
// }
// user := &structs.UserBalance{
// Username: username,
// TokenSymbol: tokenSymbol,
// Balance: *userAmout,
// }
// ctx.JSON(http.StatusOK, user)
// }
// func add(reponame string, username string, amount string) error { // 用户添加余额
// chainArgsToJsonString, err := format.ArgsJson("add", reponame, username, amount)
// if err != nil {
// return err
// }
// err = chaincode.InvokeOther(*chainArgsToJsonString) // 调用 chaincode
// return err
// }
// // Minus is to help user minus amount
// func Minus(ctx *macaron.Context, opt api.MinusTokenOption) { // 减少用户余额
// tokenSymbol := opt.TokenSymbol
// username := opt.Username
// amount := fmt.Sprintf("%v", opt.Amount)
// err := minus(tokenSymbol, username, amount)
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("minus: %v", err))
// return
// }
// userAmout, err := queryUserBalance(tokenSymbol, username) // 用户余额信息
// if err != nil {
// ctx.JSON(http.StatusInternalServerError, err)
// return
// }
// user := &structs.UserBalance{
// Username: username,
// TokenSymbol: tokenSymbol,
// Balance: *userAmout,
// }
// ctx.JSON(http.StatusOK, user)
// }
// func minus(reponame string, username string, amount string) error {
// chainArgsToJsonString, err := format.ArgsJson("minus", reponame, username, amount)
// if err != nil {
// return err
// }
// err = chaincode.InvokeOther(*chainArgsToJsonString) // 调用 chaincode
// return err
// }
// // QueryUserBalance is to query user balance by reponame and username
// func QueryUserBalance(ctx *macaron.Context) { // 查询余额
// reponame := ctx.Query("reponame")
// if reponame == "" {
// ctx.JSON(http.StatusPreconditionFailed, "reponame is not nil")
// return
// }
// username := ctx.Query("username")
// if username == "" {
// ctx.JSON(http.StatusPreconditionFailed, "username is not nil")
// return
// }
// amount, err := queryUserBalance(reponame, username)
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("queryUserBalance: %v", err))
// return
// }
// userBalance := &api.UserBalance{
// Username: username,
// TokenSymbol: reponame,
// Balance: *amount,
// }
// ctx.JSON(http.StatusOK, userBalance)
// }
// func queryUserBalance(reponame string, username string) (*uint64, error) { // 查询单次余额
// chainArgsToJsonString, err := format.ArgsJson("userBalance", reponame, username)
// if err != nil {
// return nil, err
// }
// balance, err := chaincode.InvokeBalance(*chainArgsToJsonString)
// if err != nil {
// return nil, err
// }
// return balance, err
// }
// // QueryRepoAmount is to query repository amount by reponame
// func QueryRepoAmount(ctx *macaron.Context) { // 查询项目总金额
// reponame := ctx.Query("reponame")
// if reponame == "" {
// ctx.Error(http.StatusPreconditionFailed, "reponame is not nil")
// return
// }
// username := ctx.Query("username")
// amount, err := queryRepoAmount(reponame)
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("queryRepoAmount: %v", err))
// return
// }
// userBalance := &api.Repo{
// Owner: username,
// TokenSymbol: reponame,
// TotalSupply: *amount,
// }
// ctx.JSON(http.StatusOK, userBalance)
// }
// func queryRepoAmount(reponame string) (*uint64, error) { // 查询项目总金额
// chainArgsToJsonString, err := format.ArgsJson("repoAmount", reponame)
// if err != nil {
// return nil, err
// }
// balance, err := chaincode.InvokeBalance(*chainArgsToJsonString)
// if err != nil {
// return nil, err
// }
// return balance, err
// }
// // Upload is to record commit info to blockchain
// func Upload(ctx *macaron.Context, opt api.UploadCommitOption) { // 记录 commit 信息
// commitString, err := json.Marshal(opt)
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("upload: %v", err))
// }
// chainArgsToJsonString, err := format.ArgsJson("commit", string(commitString)) // 记录 commit 信息
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("upload: %v", err))
// }
// err = chaincode.InvokeOther(*chainArgsToJsonString) // 调用 chaincode
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("upload: %v", err))
// }
// err = add(opt.Reponame, opt.Username, strconv.Itoa(opt.ModificationLines)) // 为用户加钱
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("upload: %v", err))
// }
// userAmout, err := queryUserBalance(opt.Reponame, opt.Username) // 用户余额信息
// if err != nil {
// ctx.Error(http.StatusInternalServerError, fmt.Sprintf("It is failed when query user amount: %v", err))
// return
// }
// user := &structs.UserBalance{
// Username: opt.Username,
// TokenSymbol: opt.Reponame,
// Balance: *userAmout,
// }
// ctx.JSON(http.StatusOK, user)
// }

60
routers/routes/routes.go Normal file
View File

@ -0,0 +1,60 @@
package routes
import (
"gitea.com/macaron/binding"
"gitea.com/macaron/macaron"
api "github.com/sulenn/trustie-fisco-bcos/modules/structs"
"github.com/sulenn/trustie-fisco-bcos/routers/repo"
"github.com/sulenn/trustie-fisco-bcos/routers/user"
)
// NewMacaron is to create a new macaron
func NewMacaron() *macaron.Macaron {
var m = macaron.Classic() // 经典 macaron包括 Logger、Recovery 和 Static
m.Use(macaron.Renderer()) // 数据渲染中间件,将数据渲染成 JSON 格式或 HTML 格式
RegisterRoutes(m) // 注册路由
return m
}
// RegisterRoutes is register routes
func RegisterRoutes(m *macaron.Macaron) {
bind := binding.Bind // 数据绑定和验证辅助模块
m.Get("/", func(ctx *macaron.Context) {
ctx.JSON(200, "hello world")
})
m.Group("/user", func() {
// m.Post("/register", bind(api.CreateUserOption{}), user.Register) // 注册用户
m.Get("/query/allbalance", user.SelectUserAllBalance) // 查询用户所有项目Token
m.Get("/query/balance", user.SelectUserBalance) // 查询用户单个项目Token
})
// m.Group("/channel", func() {
// m.Post("/create", bind(api.CreateChannelOption{}), channel.Create) // 创建通道
// m.Post("/join", bind(api.JoinChannelOption{}), channel.Join) // Perr 节点加入通道
// m.Group("/chaincode", func() {
// m.Post("/instantiate", bind(api.InstantiateChaincodeOption{}), channel.InstantiateChaincode) // 实例化链码
// m.Post("/invoke", bind(api.InvokeChaincodeOption{}), channel.InvokeChaincode) // 调用链码
// m.Get("/query/:channelName/:chaincodeName", channel.QueryChaincode) // 查询链码,注意 channelName 不能为 channel_name无法识别导致 api 路径出错404 错误
// })
// })
// m.Group("/chaincode", func() {
// m.Post("/install", bind(api.InstallChaincodeOption{}), chaincode.Install) // 安装链码
// })
m.Group("/repos", func() {
m.Post("/create", bind(api.CreateRepoOption{}), repo.Create) // 在区块链账本中新建一个项目
// m.Group("/amount", func() { // 和 token 值相关路由
// m.Post("/transfer", bind(api.TransferTokenOption{}), repo.Transfer) // 转账
// m.Post("/add", bind(api.AddTokenOption{}), repo.Add) // 增加账户余额
// m.Post("/minus", bind(api.MinusTokenOption{}), repo.Minus) // 减少账户余额
m.Get("/query/basic", repo.QueryBasic) // 查询账户余额
// m.Get("/repo/query", repo.QueryRepoAmount) // 查询项目总金额
// })
// m.Group("/commit", func() {
// m.Post("/upload", bind(api.UploadCommitOption{}), repo.Upload) // 记录 commit 数据
// })
})
}

109
routers/user/user.go Normal file
View File

@ -0,0 +1,109 @@
package user
import (
"fmt"
"log"
"net/http"
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
"github.com/ethereum/go-ethereum/common"
"github.com/sulenn/trustie-fisco-bcos/contract"
"github.com/sulenn/trustie-fisco-bcos/contract/opensource"
api "github.com/sulenn/trustie-fisco-bcos/modules/structs"
"gitea.com/macaron/macaron"
)
// // 用户注册
// func Register(ctx *macaron.Context, opt api.CreateUserOption) {
// var user = &api.User{opt.Username, opt.Orgname}
// ctx.JSON(200, user)
// }
// select user all balance
func SelectUserAllBalance(ctx *macaron.Context, logger *log.Logger) {
username := ctx.Query("username")
if username == "" {
ctx.JSON(http.StatusOK, api.StringEmpty)
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
logger.Panic(err)
return
}
config := &configs[0]
client, err := client.Dial(config)
if err != nil {
logger.Panic(err)
return
}
// load the contract
contractAddress := common.HexToAddress(contract.ContractAddress)
instance, err := opensource.NewOpenSource(contractAddress, client)
if err != nil {
logger.Panic(err)
return
}
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
usernames, tokenNames, balances, err := openSourceSession.SelectUserAllBalance(username) // call select API
if err != nil {
logger.Panic(err)
return
}
var userBalancelist api.UserBalanceList
for i := 0; i < len(usernames); i++ {
userBalancelist = append(userBalancelist, &api.UserBalance{User: api.User{Username: usernames[i], TokenName: tokenNames[i]}, Balance: balances[i].Uint64()})
fmt.Printf("username: %v, token_name: %v, balance: %v \n", usernames[i], tokenNames[i], balances[i])
}
ctx.JSON(http.StatusOK, userBalancelist)
}
// select user balance
func SelectUserBalance(ctx *macaron.Context, logger *log.Logger) {
username := ctx.Query("username")
tokenName := ctx.Query("tokenname")
if username == "" || tokenName == "" {
ctx.JSON(http.StatusOK, api.StringEmpty)
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
logger.Panic(err)
return
}
config := &configs[0]
client, err := client.Dial(config)
if err != nil {
logger.Panic(err)
return
}
// load the contract
contractAddress := common.HexToAddress(contract.ContractAddress)
instance, err := opensource.NewOpenSource(contractAddress, client)
if err != nil {
logger.Panic(err)
return
}
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
usernames, tokenNames, balances, err := openSourceSession.SelectUserBalance(username, tokenName) // call select API
if err != nil {
logger.Panic(err)
return
}
var userBalancelist api.UserBalanceList
for i := 0; i < len(usernames); i++ {
userBalancelist = append(userBalancelist, &api.UserBalance{User: api.User{Username: usernames[i], TokenName: tokenNames[i]}, Balance: balances[i].Uint64()})
fmt.Printf("username: %v, token_name: %v, balance: %v \n", usernames[i], tokenNames[i], balances[i])
}
ctx.JSON(http.StatusOK, userBalancelist)
}

42
sdk.crt
View File

@ -1,33 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIBgjCCASmgAwIBAgIUXNwUFb9q1P5L4faNsF+NE4T7N9MwCgYIKoZIzj0EAwIw
MIIBgzCCASmgAwIBAgIUZcjAqVQte1azeLZSOT4v8Wq5vH4wCgYIKoZIzj0EAwIw
NzEPMA0GA1UEAwwGYWdlbmN5MRMwEQYDVQQKDApmaXNjby1iY29zMQ8wDQYDVQQL
DAZhZ2VuY3kwIBcNMjEwNDEzMDIzMTA3WhgPMjEyMTAzMjAwMjMxMDdaMDExDDAK
DAZhZ2VuY3kwIBcNMjEwNDE2MDA1MjQ2WhgPMjEyMTAzMjMwMDUyNDZaMDExDDAK
BgNVBAMMA3NkazETMBEGA1UECgwKZmlzY28tYmNvczEMMAoGA1UECwwDc2RrMFYw
EAYHKoZIzj0CAQYFK4EEAAoDQgAE+M9hdPPSy9XohKr3lImPWrkh3gAsY6UUtjYu
3pdCBwCNvZy3VulMVYeYNd/Y0ypzSWb+42kYbG1S5XQXOdU/GqMaMBgwCQYDVR0T
BAIwADALBgNVHQ8EBAMCBeAwCgYIKoZIzj0EAwIDRwAwRAIgCieR5/J+R3DTFuk7
Ww2mrOsVEHKN1PAs6Gey9+GASiUCIGjrbHTVvw6Vke1YW996UKfkZGPGr7a4QEaU
wwAAbwFM
EAYHKoZIzj0CAQYFK4EEAAoDQgAEzsVoKIh1OO90KO++yIDdO1LaQh0UqOAfdrLF
sxGvEEd3vfNFnBaI4y/W2UdbX2gQjf0Wa1tbS2dfFFVObtm/OKMaMBgwCQYDVR0T
BAIwADALBgNVHQ8EBAMCBeAwCgYIKoZIzj0EAwIDSAAwRQIhANCHi1pST4tWokbE
NBKmnegdRoOEUrXSzR8XVGChehMcAiAdlGZWb1tXfzv8LXj4asrSpGVh2bWjN/iN
KAaGnq4eVg==
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIBezCCASGgAwIBAgIUO8Ok+51ev5GvY6/GCJYiGjhXh/IwCgYIKoZIzj0EAwIw
MIIBfDCCASGgAwIBAgIUSCtKH85de1vAJ4GntC+8dMVWUzkwCgYIKoZIzj0EAwIw
NTEOMAwGA1UEAwwFY2hhaW4xEzARBgNVBAoMCmZpc2NvLWJjb3MxDjAMBgNVBAsM
BWNoYWluMB4XDTIxMDQxMzAyMzEwN1oXDTMxMDQxMTAyMzEwN1owNzEPMA0GA1UE
BWNoYWluMB4XDTIxMDQxNjAwNTI0NloXDTMxMDQxNDAwNTI0NlowNzEPMA0GA1UE
AwwGYWdlbmN5MRMwEQYDVQQKDApmaXNjby1iY29zMQ8wDQYDVQQLDAZhZ2VuY3kw
VjAQBgcqhkjOPQIBBgUrgQQACgNCAARZK7bFfDKnm86Dgz/rzeBoBCT9jz6OSKKe
MwhGXO5qgzkNPoYT6ls9LfDMO0GEil+7iImyRpmElc8TnXFe3vc6oxAwDjAMBgNV
HRMEBTADAQH/MAoGCCqGSM49BAMCA0gAMEUCIQDZFhIGqz3e2oCMGvIf9rdlbWO5
JyyqraXAeFR1fQF+bAIgNe9Xk8eFHdvFRTCui3vR8tvLKRqHCEkCX7aMLAwNNmk=
VjAQBgcqhkjOPQIBBgUrgQQACgNCAAQqmqNziEBkOxb3Y+8/jEGICxF895ncmnU0
GNzhH+Qvo4TswGWYrPoy4gyeOfExlW7fP/zj28GfioPPwGE3VzIHoxAwDjAMBgNV
HRMEBTADAQH/MAoGCCqGSM49BAMCA0kAMEYCIQDdysBZ2RWEeBLshjKbtX1zk/Gj
/SJNZd55fWJYXJamyAIhAOIBkIqZ0uQpoImC3mBwUo1m7dUJNCAmlW120fZm0C8s
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIBvTCCAWSgAwIBAgIUDhho+KO+NiVPDbZ1qW0k2JuWrSAwCgYIKoZIzj0EAwIw
MIIBvjCCAWSgAwIBAgIUAguKbcVr58FSgPHWPE2zcvQqSgUwCgYIKoZIzj0EAwIw
NTEOMAwGA1UEAwwFY2hhaW4xEzARBgNVBAoMCmZpc2NvLWJjb3MxDjAMBgNVBAsM
BWNoYWluMCAXDTIxMDQxMzAyMzEwN1oYDzIxMjEwMzIwMDIzMTA3WjA1MQ4wDAYD
BWNoYWluMCAXDTIxMDQxNjAwNTI0NloYDzIxMjEwMzIzMDA1MjQ2WjA1MQ4wDAYD
VQQDDAVjaGFpbjETMBEGA1UECgwKZmlzY28tYmNvczEOMAwGA1UECwwFY2hhaW4w
VjAQBgcqhkjOPQIBBgUrgQQACgNCAAT1g2PYfplTEEgsssKEbqm1k4ugVYztSxEI
yoHC0vssQ+i1D4N6X2Gtp4BmMvNC1fnUAkpOqtdmOGxyVGDfOMOUo1MwUTAdBgNV
HQ4EFgQUKIIfjS6rQUmR+Je8SN1NBCEJA0AwHwYDVR0jBBgwFoAUKIIfjS6rQUmR
+Je8SN1NBCEJA0AwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNHADBEAiBk
R8l1Tmhbx840R0lS45drffXzsKz78n20QleYMenPdgIgQ0ssRyWL8MpZXM6orEwc
3PueajQ3tgkkxDwngCH5bdY=
VjAQBgcqhkjOPQIBBgUrgQQACgNCAATBgqh3oOWZnu6q30RFla5D5mUgzBxNvH5n
B1r0tHeBip5sRf0c6bi0sUyTwmIIeZw1icxOdMCYc7FdPEoH+To8o1MwUTAdBgNV
HQ4EFgQUw/DeoMeA72HHjWaHxx1DrRGSPeMwHwYDVR0jBBgwFoAUw/DeoMeA72HH
jWaHxx1DrRGSPeMwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNIADBFAiEA
liP0SdyqcI419xzXPK7dN75eTihUX9FfUqiAhxDp2DwCIGnR1SKLt3wBcSanxFfP
aD/Caxx6mnAqQ46t6PtedbDV
-----END CERTIFICATE-----

View File

@ -1,5 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgVOkH/t/4aFubNCE9QSQP
GbwZZqMa+yrk4ZET4ClqE9GhRANCAAT4z2F089LL1eiEqveUiY9auSHeACxjpRS2
Ni7el0IHAI29nLdW6UxVh5g139jTKnNJZv7jaRhsbVLldBc51T8a
MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgCaJU5SNgHEKKTsFpg33d
Tw9Zj2hAkDnfDLvTEJVsOXChRANCAATOxWgoiHU473Qo777IgN07UtpCHRSo4B92
ssWzEa8QR3e980WcFojjL9bZR1tfaBCN/RZrW1tLZ18UVU5u2b84
-----END PRIVATE KEY-----

View File

@ -1,7 +0,0 @@
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}