Skip to content

Commit

Permalink
bsv (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
tellnobody1 committed May 16, 2023
1 parent 691d561 commit 6510e6b
Show file tree
Hide file tree
Showing 19 changed files with 1,030 additions and 281 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
target/
network1/
**/*.rs.bk
.DS_Store
/data/
/target/
75 changes: 7 additions & 68 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "MIT"
aes = "0.3.2"
aes-ctr = "0.3.0"
block-modes = "0.3.3"
bs58 = "0.4.0"
byteorder = "1.4.3"
digest = "0.10.6"
hex = "0.4.3"
Expand All @@ -17,7 +18,6 @@ rand = "0.8.5"
rand_core = "0.6.4"
ring = "0.16.20"
ripemd = "0.1.3"
rust-base58 = "0.0.4"
rust-scrypt = "1.3.0"
secp256k1 = { version = "0.27.0", features = ["recovery", "rand-std", "bitcoin-hashes-std", "global-context"] }
serde_json = "1.0.96"
Expand Down
44 changes: 27 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
MIT License
DHARMA License

Copyright (c) 2019 flyingw
Copyright (c) 2019–2023 flyingw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
YOU CANNOT USE THIS SOFTWARE IN ANY (PROVABLE BY MONEY TRACE)
PROCESS CHAIN OF EXTERMINATING UKRAINIANS BY ANY MEANS OF FASCIST
ACTIONS AGAINST OUR TERRITORIAL INTEGRITY, CULTURAL DIVERSITY BY
APPLYING MILITARY INVASIONS, ECONOMICAL WARS, HUMANITARIAN DISASTERS,
ARTFICIAL HOLODOMORS, GENOCIDE, RAPING, LOOTING, ROBBERIES, SPREADING
FAKE INFORMATION, AND OTHER CONTEMPORARY WEAPONS OF WAR AT SCALE
OR IN INVIDIVUAL MANNER.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
YOU CANNOT USE THIS SOFTWARE BY ANY MEANS IN INTEREST OF LEGAL
ENTITIES OR INDIVIDUALS WHO IS SUPPORTING NOW OR WAS SUPPORTING
BACK THEN FASCISM, RUSCISM, COMMUNISM, CHAUVINISM, HUMILIATION,
AND OTHER SUPPRESSIVE IDEOLOGIES IN DIFFERENT EXPRESSIONS.

STOP KILLING UKRAINIANS,
THE COUNTER RENDERS TENS OF MILLIONS.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Umbrella
# umbrella

Universal cross network client to write data into blockchain.

WARN: Do not use with real networks. Test/Private only.
| network | tx | regtest | mainnet |
|:-------:|:----:|:-------:|:--------:|
| BCH | done | | |
| BSV | done | tested | api only |
| ETH | done | tested | |
| NEM | | | |

## build

```
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ rustup update
$ cargo build [--release]
```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo build [--release]
./test
```

## downloads
Expand All @@ -18,14 +23,15 @@ Released binaries

* [v0.1.0](https://github.com/flyingw/umbrella/releases/tag/v0.1.0) Does nothing. Made for internal purposes.
* [v0.2.0](https://github.com/flyingw/umbrella/releases/tag/v0.2.0) Do ETH and BCH transactions.

* [v0.3.0](https://github.com/flyingw/umbrella/releases/tag/v0.3.0) Do BSV transaction.

## local test setup

Select corresponend platform to test:

* [Bitchoin ABS](doc/bch/test-setup.md)
* [Ethereum](doc/eth/test-setup.md)
* [Bitchoin ABS](doc/bch/test-setup.md) and [run](./test_bch.sh)
* [Ethereum](doc/eth/test-setup.md) and [run](./test_eth.sh)
* [Bitcoin SV](doc/bsv/test-setup.md) and [run](./test_bsv.sh)

# links

Expand Down
132 changes: 132 additions & 0 deletions doc/bsv/test-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# setup

```sh
docker run -p 18444:18444 -p 18443:18443 -d --rm --name bitcoind -v "$PWD/data:/data" bitcoinsv/bitcoin-sv bitcoind

vim ./data/bitcoin.conf
...
regtest=1
server=1
debug=1
rpcport=18443

docker stop bitcoind
docker run -p 18444:18444 -p 18443:18443 -d --rm --name bitcoind -v "$PWD/data:/data" bitcoinsv/bitcoin-sv bitcoind

brew install bitcoin

touch ~/Library/Application\ Support/Bitcoin/bitcoin.conf
vim ~/Library/Application\ Support/Bitcoin/bitcoin.conf
regtest=1
rpcpassword=password
rpcuser=bitcoin

bitcoin-cli getnewaddress
> mhCJckDWfFvNnK2bswTBxUW49JZvJ9ARaw (public key)

bitcoin-cli generatetoaddress 200 "mhCJckDWfFvNnK2bswTBxUW49JZvJ9ARaw"

bitcoin-cli dumpprivkey "mhCJckDWfFvNnK2bswTBxUW49JZvJ9ARaw"
> cPgZDe7yAqmjDGK7vuvFrh79gjLKqGGBkuGiJrAEtmCKhJiNmCGd (private key)

bitcoin-cli listunspent 0
> "txid": "1409b3059aca971958999e70df51749d14b4280e979165b4f24ff79ddcf58dfe",
> "vout": 0,
> "amount": 25.00000000,
> "confirmations": 165,

export BALANCE="25.00000000"
export SECRET="cPgZDe7yAqmjDGK7vuvFrh79gjLKqGGBkuGiJrAEtmCKhJiNmCGd"
export OUT_HSH="1409b3059aca971958999e70df51749d14b4280e979165b4f24ff79ddcf58dfe"
export OUT_PNT="0"
export DATA="68656c6c6f2c7361696c6f72"
export NETWORK="bsv-reg"

RUST_BACKTRACE=1 cargo run -- $NETWORK \
--in_address "" \
--in_amount $BALANCE \
--secret $SECRET \
--outpoint_hash $OUT_HSH \
--outpoint_index $OUT_PNT \
--out_address "" \
--change "0" \
--dust_address "" \
--dust_amount "0" \
--data $DATA
> DEBUG - transaction hash: 1ddc1ecad78fa78007d2f80c6698c8f45ec32f4687fae40aee4d39bce3a74fc8

docker logs bitcoind

bitcoin-cli gettransaction 1ddc1ecad78fa78007d2f80c6698c8f45ec32f4687fae40aee4d39bce3a74fc8
> "hex": "..."

bitcoin-cli decoderawtransaction "..."
> {
> "value": 0.00,
> "n": 0,
> "scriptPubKey": {
> "asm": "0 OP_RETURN 68656c6c6f2c7361696c6f72",
> "hex": "006a0c68656c6c6f2c7361696c6f72",
> "type": "nulldata"
> }
> },

echo 68656c6c6f2c7361696c6f72 | xxd -r -p
> hello,sailor
```
## mainnet
```sh
export MSG="..." # your message
export DATA="$(echo $MSG | od -A n -t x1 | sed 's/ *//g')"
export NETWORK="bsv"

export ADDRESS=""
curl --location $(echo 'https://api.whatsonchain.com/v1/bsv/main/address/'$ADDRESS'/unspent')

export BALANCE=""
export SECRET=""
export OUT_HSH=""
export OUT_PNT=""

RUST_BACKTRACE=1 cargo run -- $NETWORK \
--in_address "" \
--in_amount $BALANCE \
--secret $SECRET \
--outpoint_hash $OUT_HSH \
--outpoint_index $OUT_PNT \
--out_address "" \
--change "0" \
--dust_address "" \
--dust_amount "0" \
--data $DATA
```
### api
```
curl --location 'https://api.whatsonchain.com/v1/bsv/main/tx/raw' \
--header 'Content-Type: application/json' \
--data '{
"txHex": "hex..."
}'

curl --location 'https://api.whatsonchain.com/v1/bsv/main/tx/hash/...'

open https://whatsonchain.com/tx/...
```
## notes
```sh
docker ps
docker exec -it bitcoind bash
docker run --rm --network container:bitcoind bitcoinsv/bitcoin-sv bitcoin-cli -regtest <cmd>
docker logs --follow bitcoind

bitcoin-cli getbalance
bitcoin-cli setban "172.17.0.1" "remove"

./test_bsv.sh
```
10 changes: 5 additions & 5 deletions src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ impl Units {

/// An amount of bitcoin in satoshis
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
pub struct Amount(pub i64);
pub struct Amount(pub u64);

impl Amount {
/// Creates from a given amount and unit
pub fn from(amount: f64, units: Units) -> Amount {
match units {
Units::Bch => Amount((amount * 100_000_000.) as i64),
Units::Bits => Amount((amount * 100.) as i64),
Units::Sats => Amount(amount as i64),
Units::Eth => Amount((amount * 100_000_000.) as i64),
Units::Bch => Amount((amount * 100_000_000.) as u64),
Units::Bits => Amount((amount * 100.) as u64),
Units::Sats => Amount(amount as u64),
Units::Eth => Amount((amount * 100_000_000.) as u64),
}
}

Expand Down
Loading

0 comments on commit 6510e6b

Please sign in to comment.