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
// makeBasicHost creates a LibP2P host with a random peer ID listening on the | |
// given multiaddress. It will use secio if secio is true. | |
func makeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error) { | |
// If the seed is zero, use real cryptographic randomness. Otherwise, use a | |
// deterministic randomness source to make generated keys stay the same | |
// across multiple runs | |
var r io.Reader | |
if randseed == 0 { | |
r = rand.Reader |
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
func run() error { | |
mux := makeMuxRouter() | |
httpAddr := os.Getenv("ADDR") | |
log.Println("Listening on ", os.Getenv("ADDR")) | |
s := &http.Server{ | |
Addr: ":" + httpAddr, | |
Handler: mux, | |
ReadTimeout: 10 * time.Second, | |
WriteTimeout: 10 * time.Second, | |
MaxHeaderBytes: 1 << 20, |
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
func handleGetTweets(w http.ResponseWriter, r *http.Request) { | |
var maxIDQuery string | |
var tweets []Tweet | |
vars := mux.Vars(r) | |
userID := vars["id"] | |
// httpClient will automatically authorize http.Requests | |
httpClient := config.Client(oauth1.NoContext, token) | |
Outer: |
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
func main() { | |
err := godotenv.Load() | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Load API credentials | |
config = oauth1.NewConfig(os.Getenv("APIKEY"), os.Getenv("APISECRET")) | |
token = oauth1.NewToken(os.Getenv("TOKEN"), os.Getenv("TOKENSECRET")) |
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
// makeMuxRouter defines and creates routes | |
func makeMuxRouter() http.Handler { | |
muxRouter := mux.NewRouter() | |
muxRouter.HandleFunc("/{id}", handleGetTweets).Methods("GET") | |
return muxRouter | |
} | |
func respondWithError(err error, w http.ResponseWriter) { | |
log.Println(err) | |
w.WriteHeader(500) |
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
// Tweet is a collection of important info in each Tweet | |
type Tweet struct { | |
Date string `json:"created_at"` | |
Text string `json:"text"` | |
ID string `json:"id_str"` | |
} | |
var config *oauth1.Config | |
var token *oauth1.Token |
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
"regexp" |
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
func (s *SmartContract) changeCarOwner(APIstub shim.ChaincodeStubInterface, args []string) sc.Response { | |
if len(args) != 2 { | |
return shim.Error("Incorrect number of arguments. Expecting 2") | |
} | |
carAsBytes, _ := APIstub.GetState(args[0]) | |
car := Car{} | |
json.Unmarshal(carAsBytes, &car) |
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
// Block represents each 'item' in the blockchain | |
type Block struct { | |
Index int | |
Timestamp string | |
BPM int | |
Hash string | |
PrevHash string | |
Validator string | |
} |
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
function transfer(address _to, uint256 _value) { | |
require(balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]); | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
} |
NewerOlder