-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Sample application using bbclib-go | ||
====== | ||
|
||
## install | ||
|
||
### in the case of using "go get" | ||
|
||
``` | ||
go get -u -d github.com/quvox/bbclib-go | ||
pushd ${GOPATH}/src/github.com/quvox/bbclib-go | ||
bash prepare.sh | ||
popd | ||
go install github.com/quvox/bbclib-go | ||
``` | ||
|
||
The important point is adding "-d" in the first go get. This means downloads repository only. Before installing, libbbcsig.a needs to be built. | ||
|
||
### in the case of vendoring through "dep" | ||
|
||
``` | ||
dep init | ||
pushd vendor/github.com/quvox/bbclib-go | ||
bash prepare.sh | ||
popd | ||
go install github.com/quvox/bbclib-go | ||
``` | ||
|
||
The difference between "go get" and "dep" is just a directory including libraries. | ||
|
||
### Utility script | ||
|
||
In the src/main directory, there is "prepare_libbbcsig.h" for building libbbcsig.a in the case of both "go get" and "dep". | ||
|
||
|
||
## Build app | ||
|
||
In src/main directory, | ||
|
||
``` | ||
go run main.go | ||
``` | ||
|
||
or | ||
|
||
``` | ||
go build main.go | ||
./main | ||
``` | ||
|
||
then you will see the string output of a sample transaction. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/quvox/bbclib-go" | ||
"io/ioutil" | ||
) | ||
|
||
func main() { | ||
assetGroupID := bbclib.GetIdentifierWithTimestamp("assetGroupID", 32) | ||
u1 := bbclib.GetIdentifierWithTimestamp("user1", 32) | ||
u2 := bbclib.GetIdentifierWithTimestamp("user2", 32) | ||
keypair1 := bbclib.GenerateKeypair(bbclib.KeyTypeEcdsaP256v1, 4) | ||
keypair2 := bbclib.GenerateKeypair(bbclib.KeyTypeEcdsaSECP256k1, 4) | ||
|
||
txobj := bbclib.MakeTransaction(3, 0, true, 32) | ||
bbclib.AddEventAssetBodyString(txobj, 0, &assetGroupID, &u1, "teststring!!!!!") | ||
txobj.Events[0].AddMandatoryApprover(&u1) | ||
filedat, _ := ioutil.ReadFile("./asset_test.go") | ||
bbclib.AddEventAssetFile(txobj, 1, &assetGroupID, &u2, &filedat) | ||
txobj.Events[1].AddMandatoryApprover(&u2) | ||
datobj := map[string]string{"param1": "aaa", "param2": "bbb", "param3": "ccc"} | ||
bbclib.AddEventAssetBodyObject(txobj, 2, &assetGroupID, &u1, &datobj) | ||
txobj.Events[2].AddMandatoryApprover(&u1) | ||
|
||
txobj.Witness.AddWitness(&u1) | ||
txobj.Witness.AddWitness(&u2) | ||
|
||
bbclib.SignToTransaction(txobj, &u1, &keypair1) | ||
bbclib.SignToTransaction(txobj, &u2, &keypair2) | ||
|
||
fmt.Println("-------------transaction--------------") | ||
fmt.Printf("%v", txobj.Stringer()) | ||
fmt.Println("--------------------------------------") | ||
|
||
dat, err := txobj.Pack() | ||
if err != nil { | ||
fmt.Printf("failed to serialize transaction object (%v)", err) | ||
} | ||
fmt.Printf("Packed data: %x", dat) | ||
|
||
obj2 := bbclib.BBcTransaction{} | ||
obj2.Unpack(&dat) | ||
obj2.Digest() | ||
if result := obj2.Signatures[0].Verify(obj2.TransactionID); !result { | ||
fmt.Println("Verification failed..") | ||
} | ||
|
||
if bytes.Compare(txobj.Events[0].Asset.AssetID, obj2.Events[0].Asset.AssetID) != 0 || | ||
bytes.Compare(txobj.TransactionID, obj2.TransactionID) != 0 { | ||
fmt.Println("Not recovered correctly...") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
REPO=github.com/quvox/bbclib-go | ||
|
||
#go get -u -d ${REPO} | ||
|
||
if [ -d ./vendor/${REPO} ]; then | ||
WORKINGDIR=./vendor/${REPO} | ||
elif [ -d ${GOPATH}/src/${REPO} ]; then | ||
WORKINGDIR=${GOPATH}/src/${REPO} | ||
else | ||
echo "No bbclib-go repository found..." | ||
exit 1 | ||
fi | ||
|
||
cd ${WORKINGDIR} | ||
|
||
if [ $# -eq 1 ] && [ $1 = "aws" ]; then | ||
bash prepare.sh aws | ||
else | ||
bash prepare.sh | ||
fi | ||
|
||
# go install ${REPO} |