Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Sutula <[email protected]>
  • Loading branch information
asutula committed Aug 13, 2021
1 parent 5cc6abc commit 53e6962
Show file tree
Hide file tree
Showing 27 changed files with 2,701 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .bingo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# Ignore everything
*

# But not these files:
!.gitignore
!*.mod
!README.md
!Variables.mk
!variables.env

*tmp.mod
14 changes: 14 additions & 0 deletions .bingo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Project Development Dependencies.

This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo.

* Run `bingo get` to install all tools having each own module file in this directory.
* Run `bingo get <tool>` to install <tool> that have own module file in this directory.
* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $(<upper case tool name>) variable where <tool> is the .bingo/<tool>.mod.
* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool.
* For go: Import `.bingo/variables.go` to for variable names.
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies.

## Requirements

* Go 1.14+
31 changes: 31 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.5.1. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
GO ?= $(shell which go)

# Below generated variables ensure that every time a tool under each variable is invoked, the correct version
# will be used; reinstalling only if needed.
# For example for bingo variable:
#
# In your main Makefile (for non array binaries):
#
#include .bingo/Variables.mk # Assuming -dir was set to .bingo .
#
#command: $(BINGO)
# @echo "Running bingo"
# @$(BINGO) <flags/args..>
#
BINGO := $(GOBIN)/bingo-v0.5.1
$(BINGO): $(BINGO_DIR)/bingo.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/bingo-v0.5.1"
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=bingo.mod -o=$(GOBIN)/bingo-v0.5.1 "github.com/bwplotka/bingo"

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.41.1
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/golangci-lint-v1.41.1"
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.41.1 "github.com/golangci/golangci-lint/cmd/golangci-lint"

5 changes: 5 additions & 0 deletions .bingo/bingo.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.16

require github.com/bwplotka/bingo v0.5.1
1 change: 1 addition & 0 deletions .bingo/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files.
5 changes: 5 additions & 0 deletions .bingo/golangci-lint.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.16

require github.com/golangci/golangci-lint v1.41.1 // cmd/golangci-lint
14 changes: 14 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.5.1. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
GOBIN=${GOBIN:=$(go env GOBIN)}

if [ -z "$GOBIN" ]; then
GOBIN="$(go env GOPATH)/bin"
fi


BINGO="${GOBIN}/bingo-v0.5.1"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.41.1"

23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
name: compile & test
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
- name: Check out code
uses: actions/checkout@v1
- name: Lint
run: make lint
- name: Build
run: make build
- name: Test
run: make test
25 changes: 25 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
linters-settings:
misspell:
locale: US

linters:
enable:
- golint
- misspell
- bodyclose
- unconvert
- goconst
- goimports
- unparam
- whitespace
- godot
- lll

issues:
exclude-use-default: false

exclude:
- stutters

run:
timeout: 30m
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include .bingo/Variables.mk

lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run
.PHONYY: lint

build:
go build ./...
.PHONY: build

test:
go test ./...
.PHONY: test
100 changes: 99 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,100 @@
# near-api-go
NEAR client written in Go

[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)

A NEAR client written in Go

The goal of this project is to provide a fully featured NEAR cleint in Go. There is support for all NEAR RPC requests, including those that use signed transactions. Of course, there is room for improvement, especially with integration testing and a fully featured `KeyStore`, so please give it a spin and feel free to open a PR to help us improve the library.

We're currently relying on [our fork of go-ethereum's JSON RPC client](https://github.com/textileio/go-ethereum) that adds support for named RPC parameters. That work is [pending PR](https://github.com/ethereum/go-ethereum/pull/22656) merge into their master branch.

## Table of Contents

- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Maintainers](#maintainers)
- [Contributing](#contributing)
- [License](#license)

## Install

```
go get github.com/textileio/near-api-go
```

## Usage

Import the required modules.

```golang
import (
"github.com/textileio/near-api-go"
"github.com/textileio/near-api-go/keys"
"github.com/textileio/near-api-go/transaction"
"github.com/textileio/near-api-go/types"
"github.com/ethereum/go-ethereum/rpc"
)

```

Configure and create an API client.

```golang
rpcClient, err := rpc.DialContext(ctx, "https://rpc.testnet.near.org")

keyPair, err := keys.NewKeyPairFromString(
"ed25519:...",
)

config := &types.Config{
RPCClient: rpcClient,
Signer: keyPair, // Currently we use a key pair directly as a signer.
NetworkID: "testnet",
}

client, err := api.NewClient(config)
```

Interact with top level functions like `CallFunction`, for example. It can be used for calling non-signed "view" functions.

```golang
res, err := client.CallFunction(ctx, "<account id>", "myFunction", CallFunctionWithFinality("final"))
```

Most other functionality is provided by the `Account` sub module. For example, you can call state-modifying functions that are sent as signed transactions, and even include a deposit while you're at it.

```golang
deposit, ok := (&big.Int{}).SetString("1000000000000000000000000", 10)
res, err := c.NearClient.Account("<client account id>").FunctionCall(
ctx,
<contract account id>,
"myTxnFunction",
transaction.FunctionCallWithArgs(map[string]interface{}{
"arg1": value1,
"arg2": value2
}),
transaction.FunctionCallWithDeposit(*deposit),
)
```

Check out the [API docs](https://pkg.go.dev/github.com/textileio/near-api-go) to see all that is possible.

## API

[https://pkg.go.dev/github.com/textileio/near-api-go](https://pkg.go.dev/github.com/textileio/near-api-go)

## Maintainers

[@asutula](https://github.com/asutula)

## Contributing

PRs accepted.

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

MIT © 2021 Textile
Loading

0 comments on commit 53e6962

Please sign in to comment.