Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and scalability of a declarative transaction model such as Bitcoin's.

* [TxVM White Paper](https://chain.com/assets/txvm.pdf)
* [TxVM Specification](specifications/txvm.md)
* [Documentation for TxVM command line tools](https://godoc.org/github.com/chain/txvm)
* [Documentation for TxVM command line tools](https://godoc.org/github.com/bobg/txvm)
* [Presentation](https://www.youtube.com/watch?v=qY_0MJDMBNY)
and
[slides](https://cyber.stanford.edu/sites/default/files/txvm_stanford_jan24.pdf)
Expand All @@ -31,13 +31,13 @@ Details [here](https://golang.org/cmd/go/#hdr-Preliminary_module_support).
Run the following command:

```sh
go get github.com/chain/txvm/...
go get github.com/bobg/txvm/...
```

## Testing

```sh
go test -race -cover github.com/chain/txvm/...
go test -race -cover github.com/bobg/txvm/...
```

## Usage
Expand Down Expand Up @@ -70,7 +70,7 @@ To compute its transaction log:

For more on the commands `txvm` makes available,
you can check out the
[documentation](https://godoc.org/github.com/chain/txvm).
[documentation](https://godoc.org/github.com/bobg/txvm).

## Contributing

Expand Down
38 changes: 9 additions & 29 deletions cmd/asm/asm.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
package main

import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/chain/txvm/protocol/txvm/asm"
"github.com/bobg/txvm/cmd/internal/asm"
)

func main() {
doDisasm := flag.Bool("d", false, "disassemble")
flag.Parse()
if *doDisasm {
disassemble()
} else {
assemble()
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
}

func assemble() {
src, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
res, err := asm.Assemble(string(src))
if err != nil {
panic(err)
}
os.Stdout.Write(res)
}
func run() error {
doDisasm := flag.Bool("d", false, "disassemble")
flag.Parse()

func disassemble() {
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
dis, err := asm.Disassemble(b)
if err != nil {
panic(err)
}
fmt.Println(dis)
return asm.Run(context.Background(), *doDisasm, nil)
}
2 changes: 0 additions & 2 deletions cmd/asm/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*

Command asm assembles and disassembles

Usage:
Expand All @@ -18,6 +17,5 @@ Examples:

$ echo "6101303833" | hex -d | asm -d
[1 verify] contract call

*/
package main
48 changes: 17 additions & 31 deletions cmd/assetid/assetid.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,36 @@
package main

import (
"encoding/hex"
"context"
"flag"
"fmt"
"os"
"strconv"

"github.com/chain/txvm/crypto/ed25519"
"github.com/chain/txvm/protocol/txbuilder/standard"
"github.com/bobg/txvm/cmd/internal/assetid"
"github.com/bobg/txvm/errors"
)

func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
}

func run() error {
tagHex := flag.String("t", "", "hex asset tag")
help := flag.Bool("h", false, "help")
version := flag.Int("v", 2, "asset contract version")
flag.Parse()
if *help {
usage(0)
}
tag, err := hex.DecodeString(*tagHex)
must(err)
if flag.NArg() < 2 {
usage(1)
}
quorum, err := strconv.Atoi(flag.Arg(0))
must(err)
var pubkeys []ed25519.PublicKey
for i := 1; i < flag.NArg(); i++ {
pubkey, err := hex.DecodeString(flag.Arg(1))
must(err)
pubkeys = append(pubkeys, ed25519.PublicKey(pubkey))
}
assetID := standard.AssetID(*version, quorum, pubkeys, tag)
_, err = os.Stdout.Write(assetID[:])
must(err)
}

func usage(exitval int) {
fmt.Println("Usage:")
fmt.Printf("\t%s [-t taghex] quorum pubkey1hex pubkey2hex ...\n", os.Args[0])
os.Exit(exitval)
}
if flag.NArg() == 0 {
return fmt.Errorf("must provide quorum and at least one public key")
}

func must(err error) {
quorum, err := strconv.Atoi(flag.Arg(0))
if err != nil {
panic(err)
return errors.Wrap(err, "parsing quorum")
}

return assetid.Run(context.Background(), *tagHex, *version, quorum, flag.Args()[1:])
}
2 changes: 0 additions & 2 deletions cmd/assetid/doc.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/*

Command assetid produces an asset ID from an initial contract program
and an optional asset tag (default empty).

Usage:

assetid [-t taghex] [-v contract-version] quorum pubkey1hex pubkey2hex ...

*/
package main
77 changes: 11 additions & 66 deletions cmd/bcstate/bcstate.go
Original file line number Diff line number Diff line change
@@ -1,82 +1,27 @@
package main

import (
"context"
"flag"
"io"
"io/ioutil"
"log"
"fmt"
"os"

"github.com/chain/txvm/protocol/bc"
"github.com/chain/txvm/protocol/state"
"github.com/bobg/txvm/cmd/internal/bcstate"
)

func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
}

func run() error {
var (
blockFile = flag.String("block", "", "filename containing block to apply")
stateFile = flag.String("state", "", "filename containing previous state")
)

flag.Parse()

if *blockFile == "-" && *stateFile == "-" {
log.Fatal("only one of -block and -state may be -")
}

blockInp := getReader(*blockFile)
if blockInp != nil {
defer blockInp.Close()
}

stateInp := getReader(*stateFile)
if stateInp != nil {
defer stateInp.Close()
}

var snapshot *state.Snapshot

if stateInp == nil {
snapshot = state.Empty()
} else {
b, err := ioutil.ReadAll(stateInp)
must(err)
snapshot = new(state.Snapshot)
err = snapshot.FromBytes(b)
must(err)
}

if blockInp != nil {
b, err := ioutil.ReadAll(blockInp)
must(err)
var block bc.Block
err = block.FromBytes(b)
must(err)
err = snapshot.ApplyBlock(block.UnsignedBlock)
if err != nil {
log.Fatal(err)
}
}

b, err := snapshot.Bytes()
must(err)
os.Stdout.Write(b)
}

func getReader(arg string) io.ReadCloser {
switch arg {
case "":
return nil
case "-":
return os.Stdin
default:
f, err := os.Open(arg)
must(err)
return f
}
}

func must(err error) {
if err != nil {
panic(err)
}
return bcstate.Run(context.Background(), *blockFile, *stateFile, flag.Args())
}
2 changes: 0 additions & 2 deletions cmd/bcstate/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*

Command bcstate reads and writes blockchain state, optionally applying
a block.

Expand All @@ -16,6 +15,5 @@ BLOCKFILE is applied to it, and the resulting updated state is written
to standard output. If STATEFILE is not specified then a new blank
state snapshot is used. If BLOCKFILE is not specified then the input
state is simply copied to standard output.

*/
package main
Loading