Giter VIP home page Giter VIP logo

go's Introduction

Stellar
Creating equitable access to the global financial system

Stellar Go Monorepo

master GitHub workflow GoDoc Go Report Card

This repo is the home for all of the public Go code produced by the Stellar Development Foundation.

This repo contains various tools and services that you can use and deploy, as well as the SDK you can use to develop applications that integrate with the Stellar network.

Package Index

  • Horizon Server: Full-featured API server for Stellar network
  • Go Horizon SDK - horizonclient: Client for Horizon server (queries and transaction submission)
  • Go Horizon SDK - txnbuild: Construct Stellar transactions and operations
  • Ticker: An API server that provides statistics about assets and markets on the Stellar network
  • Keystore: An API server that is used to store and manage encrypted keys for Stellar client applications
  • Servers for Anchors & Financial Institutions
    • Compliance Server: Allows financial institutions to exchange KYC information
    • Federation Server: Allows organizations to provide addresses for users (jane*examplebank.com)

Dependencies

This repository is officially supported on the last two releases of Go.

It depends on a number of external dependencies, and uses Go Modules to manage them. Running any go command will automatically download dependencies required for that operation.

You can choose to checkout this repository into a GOPATH or into any directory.

Directory Layout

In addition to the other top-level packages, there are a few special directories that contain specific types of packages:

  • clients contains packages that provide client packages to the various Stellar services.
  • exp contains experimental packages. Use at your own risk.
  • handlers contains packages that provide pluggable implementors of http.Handler that make it easier to incorporate portions of the Stellar protocol into your own http server.
  • support contains packages that are not intended for consumption outside of Stellar's other packages. Packages that provide common infrastructure for use in our services and tools should go here, such as db or log.
  • support/scripts contains single-file go programs and bash scripts used to support the development of this repo.
  • services contains packages that compile to applications that are long-running processes (such as API servers).
  • tools contains packages that compile to command line applications.

Each of these directories have their own README file that explain further the nature of their contents.

Other packages

In addition to the packages described above, this repository contains various packages related to working with the Stellar network from a go program. It's recommended that you use godoc to browse the documentation for each.

Package source layout

While much of the code in individual packages is organized based upon different developers' personal preferences, many of the packages follow a simple convention for organizing the declarations inside of a package that aim to aid in your ability to find code.

In each package, there may be one or more of a set of common files:

  • errors.go: This file should contains declarations (both types and vars) for errors that are used by the package.
  • example_test.go: This file should contains example tests, as described at https://blog.golang.org/examples.
  • main.go/internal.go (deprecated): Older packages may have a main.go (public symbols) or internal.go (private symbols). These files contain, respectively, the exported and unexported vars, consts, types and funcs for the package. New packages do not follow this pattern, and instead follow the standard Go convention to co-locate structs and their methods in the same files.
  • main.go (new convention): If present, this file contains a main function as part of an executable main package.

In addition to the above files, a package often has files that contains code that is specific to one declared type. This file uses the snake case form of the type name (for example loggly_hook.go would correspond to the type LogglyHook). This file should contain method declarations, interface implementation assertions and any other declarations that are tied solely to that type.

Each non-test file can have a test counterpart like normal, whose name ends with _test.go. The common files described above also have their own test counterparts... for example internal_test.go should contains tests that test unexported behavior and more commonly test helpers that are unexported.

Generally, file contents are sorted by exported/unexported, then declaration type (ordered as consts, vars, types, then funcs), then finally alphabetically.

Test helpers

Often, we provide test packages that aid in the creation of tests that interact with our other packages. For example, the support/db package has the support/db/dbtest package underneath it that contains elements that make it easier to test code that accesses a SQL database. We've found that this pattern of having a separate test package maximizes flexibility and simplifies package dependencies.

Contributing

Contributions are welcome! See CONTRIBUTING.md for more details.

Developing

See GUIDE_FOR_DEVELOPERS.md for helpful instructions for getting started developing code in this repository.

go's People

Contributors

2opremio avatar abuiles avatar accordeiro avatar aditya1702 avatar bartekn avatar debnil avatar erika-sdf avatar graydon avatar howardtw avatar ire-and-curses avatar jacekn avatar jakeurban avatar leighmcculloch avatar marcelosalloum avatar marta-lokhova avatar mollykarcher avatar monsieurnicolas avatar mwtzzz avatar nikhilsaraf avatar nullstyle avatar poliha avatar shaptic avatar sreuland avatar tamirms avatar theaeolianmachine avatar tomerweller avatar tomquisel avatar tsachiherman avatar urvisavla avatar zagan202 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go's Issues

error needs to be more helpful

SubmitTransaction is returning: "decode response failed: Horizon error"
This isn't helpful. It should have the full response from horizon so I can figure out what is going wrong.

`history_trades_sold_amount_check` constraint violation

@poliha's horizon is stuck because of this error:

time="2017-10-18T10:22:32Z" level=error msg="import session failed: failed to exec sql: exec failed: pq: new row for relation "history_trades" violates check constraint "history_trades_sold_amount_check"" pid=1267

It looks like horizon is unable to process operation: 60415642800492545 because one of it's effects violates history_trades_sold_amount_check constraint on history_trades table:

CONSTRAINT history_trades_sold_amount_check CHECK ((sold_amount > 0))

Don't see how to "GetData()" on the Managed Data of an Account

I don't see how to retrieve the values from the Managed Data section of an Account object.

After executing the SetData(key_string, value_bytes) operation on an Account (which succeeds) I expected to see something like Account.GetData(key_string) or Account.ManagedData[key_string] on the object that comes back from Client.LoadAccount(account_id).

The Horizon server includes the values in the data field on the Account's JSON response object.
You can see an example on Account GCORTO4MOGRSOZOVYELTL5SDTZCGLE2YA7YDYV7X5EMDTHARSMEAOZJQ in the Test Network here:
https://www.stellar.org/laboratory/#explorer?resource=accounts&endpoint=single&values=eyJhY2NvdW50X2lkIjoiR0NPUlRPNE1PR1JTT1pPVllFTFRMNVNEVFpDR0xFMllBN1lEWVY3WDVFTURUSEFSU01FQU9aSlEifQ%3D%3D&network=test

Here's a trimmed version of the full response:

{
  "_links": {
 ...
  },
  "id": "GCORTO4MOGRSOZOVYELTL5SDTZCGLE2YA7YDYV7X5EMDTHARSMEAOZJQ",
  "paging_token": "",
  "account_id": "GCORTO4MOGRSOZOVYELTL5SDTZCGLE2YA7YDYV7X5EMDTHARSMEAOZJQ",
  "sequence": "993559079550998",
  "subentry_count": 5,
  "thresholds": {
    "low_threshold": 0,
    "med_threshold": 0,
    "high_threshold": 0
  },
  "flags": {
    "auth_required": false,
    "auth_revocable": false
  },
  "balances": [
...
  ],
  "signers": [
...
  ],
  "data": {
    "..": "R0NCVkwzU1FGRVZLUkxQNkFKNDdVS0tXWUVCWTQ1V0hBSkhDRVpLVldNVEdNQ1Q0SDROS1FZTEg=",
    "SecondString": "R0NCVkwzU1FGRVZLUkxQNkFKNDdVS0tXWUVCWTQ1V0hBSkhDRVpLVldNVEdNQ1Q0SDROS1FZTEg="
  }
}

I also looked at the JavaScript SDK to see if I could figure out the expected pattern but data retrieval Operations seems to be missing from there as well (but perhaps the JSON response object loads more natively in that SDK).

Port horizon into here

  • copy stellar/horizon -> stellar/go/services/horizon
  • deal with the dependencies (GB -> go build)
  • change stellar/docs, stellar/developers to point to the new horizon url
  • update stellar/horizon with a "repository has moved" message
  • merge any changes made to stellar/horizon during the port (1 change)
  • update the documentation how to build horizon
  • horizon tests to use Postgres() for parallelization (remove horizon script from .travis.yml)

Frontend SDK

As described in design doc.

  • Recovery transactions

Getting started documentation broken

The code examples on: https://www.stellar.org/developers/guides/get-started/create-account.html are broken.

Let's take the first one as an example:

package main

import (
	"log"

	"github.com/stellar/go/keypair"
)

func main() {
	pair, err := keypair.Random()
	if err != nil {
		log.Fatal(err)
	}

	log.Println(pair.secret())
	// SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7
	log.Println(pair.Address())
	// GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB
}

I don't think it has ever worked as pair.secret is not an exposed method. On top of that there's no function anymore called secret. pair.Seed() maybe?

The second example has broken imports (http which should be net/http) and expects code from the first example (pair.Address()) to be present. At last fmt.Println(body) does not make much sense. Maybe a fmt.Println(string(body)) would suffice here.
I suggest either remove the imports and main? or show a fully working example?

I haven't ran more examples through yet, but i have a feeling there's more broken stuff.

Besides, adding comments to exposed methods/functions is always a nice bonus ;-)

➜  github.com/stellar/go/keypair git:(master) ✗ golint
from_address.go:19:1: exported method FromAddress.Address should have comment or be unexported
from_address.go:23:1: exported method FromAddress.Hint should have comment or be unexported
from_address.go:28:1: exported method FromAddress.Verify should have comment or be unexported
from_address.go:42:1: exported method FromAddress.Sign should have comment or be unexported
from_address.go:46:1: exported method FromAddress.SignDecorated should have comment or be unexported
full.go:11:6: exported type Full should have comment or be unexported
full.go:15:1: exported method Full.Address should have comment or be unexported
full.go:19:1: exported method Full.Hint should have comment or be unexported
full.go:24:1: exported method Full.Seed should have comment or be unexported
full.go:28:1: exported method Full.Verify should have comment or be unexported
full.go:42:1: exported method Full.Sign should have comment or be unexported
full.go:47:1: exported method Full.SignDecorated should have comment or be unexported

About the lint messages, i could do a pull request on that, once i have read up a bit more on the stellar documentation :)

Add ticker endpoint

select a pair you are interested in and returns the HLOC+V for the last 24 hours

archivist does not report about missing files

Here is example with ledger-00378d7f.xdr.gz missing on core_live_003:

wget http://history.stellar.org/prd/core-live/core_live_003/ledger/00/37/8d/ledger-00378d7f.xdr.gz
--2017-08-25 12:25:43--  http://history.stellar.org/prd/core-live/core_live_003/ledger/00/37/8d/ledger-00378d7f.xdr.gz
Resolving history.stellar.org (history.stellar.org)... 52.218.16.98
Connecting to history.stellar.org (history.stellar.org)|52.218.16.98|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-08-25 12:25:44 ERROR 404: Not Found.

stellar-archivist does not catch this error

./stellar-archivist --low 3600000 --high 3700000 scan --verify --thorough http://history.stellar.org/prd/core-live/core_live_003/
2017/08/25 12:23:23 Scanning checkpoint files in range: [0x0036ee3f, 0x0038753f]
2017/08/25 12:23:35 Archive: 1564 history, 1564 ledger, 968 transactions, 0 results, 0 scp
2017/08/25 12:23:55 Checkpoint files scanned with 0 errors
2017/08/25 12:23:55 Archive: 1564 history, 1564 ledger, 1564 transactions, 1564 results, 1564 scp
2017/08/25 12:24:01 Archive: 312 buckets total, 312 referenced
2017/08/25 12:24:01 Examining checkpoint files for gaps
2017/08/25 12:24:01 Examining buckets referenced by checkpoints
2017/08/25 12:24:01 No checkpoint files missing in range [0x0036ee3f, 0x0038753f]
2017/08/25 12:24:01 No missing buckets referenced in range [0x0036ee3f, 0x0038753f]
2017/08/25 12:24:01 Error: mismatched hash on ledger header 0x0037983f: expected 214bba8213a2e58e3e40ba1ff57882306b97c305404c5f5d2506917be56e48cf, got 0000000000000000000000000000000000000000000000000000000000000000
2017/08/25 12:24:01 Error: 1 ledger headers (of 63168 checked) have unexpected hashes
2017/08/25 12:24:01 Verified 63168 transaction sets have expected hashes
2017/08/25 12:24:01 Verified 63168 transaction result sets have expected hashes
2017/08/25 12:24:01 Verified 312 buckets have expected hashes
2017/08/25 12:24:01 Detected 1 objects with unexpected hashes

Create simple asset table

As a beginning, and to help with this issue: #103. Maybe we should start with a simple compact history_assets table that will serve as a lookup table, something like this:

CREATE TABLE history_assets (
  id SERIAL PRIMARY KEY ,
  asset_type VARCHAR(64) NOT NULL,
  asset_code VARCHAR(12) NOT NULL,
  asset_issuer VARCHAR(56) NOT NULL,
  UNIQUE(asset_type, asset_code, asset_issuer)
);

Recovery transactions

Send recovery transactions in case user's keys are lost, as described in design doc.

  • Backend
  • Frontend

tls: failed to parse private key

I bought an SSL, key is one I generate using openssl, and crt is downloaded from CA:

I generated using a password.

certificate-file = "mm_hhprint_com.crt"
private-key-file = "mm.hhprint.com.key"

but I got this:

level=error msg="failed to start server: tls: failed to parse private key" pid=14328

Am I missing out something?

Prevent address exhaustion attack

This is theoretical attack but should be discussed and at least mentioned in a README file.

BIP-32 allows generating up to 2,147,483,648 - 1 addresses using a single public master key. In theory, someone could send lots of requests and generates lots of unused addresses.

RPS Exhausted in
100 248 days
1000 24 days
10000 59 hours

Possible solutions:

  • Use m / purpose' / coin_type' derivation path and generate a new account when address_index level becomes exhausted.
  • Rate limiting (implemented in bifrost?)
  • Captcha (implemented in bifrost?)

gosdk StreamRange

StreamEffectsRange
StreamTransactionsRange
etc
would allow you to fetch all the resources between two points. Useful if you want to calculate daily volume for example.

Horizon: Aggregated Trade History API

Moving this discussion here.
To serve StellarTerm and other exchanges, Horizon will expose an API to access aggregated historical information on trades.

Request params:

  • base_asset_issuer
  • base_asset_type
  • base_asset_code
  • counter_asset_issuer
  • counter_asset_type
  • counter_asset_code
  • start_timestamp
  • end_timestamp
  • resolution

Inspired by other exchanges, the available resolutions would be: 5-mins, 10-min, 30-min, 2-hr, 4-hr, 1-day. (anymore?)

The return value would contain an array of records.

Record fields:

  • timestamp
  • open
  • close
  • high
  • low
  • base_volume
  • counter_volume
  • trade_count

Modify the history_trades table to be friendlier for price aggregation

In preparation for #94, modifying the history_trades table can assist in simpler aggregation.
The main two issues to handle:

  1. history_trades has no time of creation, only operation id. This requires joining with the history_ledgers to get exact times.
  2. The separation of buyers and sellers is not relevant for aggregation and forces every query to handle both possible directions.

Unmarshaling malicious data with variable-length array without specified size can lead to extensive memory usage

There is a bug in go-xdr (I wasn't able to create an issue there) when trying to unmarshal variable-length array without specified size. Take a look at this union:

union StellarMessage switch (MessageType type)
{
  // ...

case GET_PEERS:
    void;
case PEERS:
    PeerAddress peers<>;

  // ...
}

We can create a special StellarMessage that looks like:

$ echo "AAAABX///9AAAAAAAAECAwAAAFAAAABk" | base64 -D | hexdump -C
00000000  00 00 00 05 7f ff ff d0  00 00 00 00 00 01 02 03  |................|
                      ^^^^^^^^^^^
00000010  00 00 00 50 00 00 00 64                           |...P...d|
00000018

Bytes marked with ^ represent the size of an array, which should be 1 since it contains only one address, but it has been changed to some very large number. As a result go-xdr is trying to allocate a large chunk of memory for the array that in reality is really small. Here's a little proof-of-concept:

package main

import (
  "github.com/stellar/go/xdr"
)

func main() {
  var message xdr.StellarMessage
  xdr.SafeUnmarshalBase64("AAAABX///9AAAAAAAAECAwAAAFAAAABk", &message)
}

A fix should check if the number of remaining bytes is less than or equal the specified size before allocating memory (you can check how it's works in xdrpp).

TransactionBuilder.Sign should return an error

Currently the code doesn't return an error, so it can fail (like it is, in my code) at one of the result.Mutate() and the entire operation will fail, but with a different error than the one that has actually ocurred first.

In my case, it is failing at result.Mutate(b), then what happens is that the TransactionBuilder pointer is not being copied to TransactionEnvelopeBuilder and thus txe.Base64() fails when it tries to check the underlying TransactionEnvelope for a NetworkPassphrase. The passphrase is not there only because the last step has failed totally.

Actual and Expected argument for `assert.Equal` are switched.

Probably in all test files (I only picked a few to check). The arguments are switched.
the correct syntax is assert.Equal(t, expected, actual)
but I see a lot assert.Equal(t, actual, expected)

This is no big issue, but good to know when you are debugging.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.