Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Goshimmer_without_tipselection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COLLET Ismael
Goshimmer_without_tipselection
Commits
b4d04a3d
Unverified
Commit
b4d04a3d
authored
4 years ago
by
Angelo Capossele
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update double-spend tool (#664)
*
Update double-spend tool *
Fix linter warnings *
Fix review comments
parent
183b4f44
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/double-spend/double-spend.go
+87
-32
87 additions, 32 deletions
tools/double-spend/double-spend.go
with
87 additions
and
32 deletions
tools/double-spend/double-spend.go
+
87
−
32
View file @
b4d04a3d
...
...
@@ -3,6 +3,7 @@ package main
import
(
"fmt"
"net/http"
"sync"
"time"
"github.com/iotaledger/goshimmer/client"
...
...
@@ -12,53 +13,107 @@ import (
valuepayload
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/wallet"
"github.com/mr-tron/base58"
)
func
main
()
{
clients
:=
make
([]
*
client
.
GoShimmerAPI
,
2
)
client
:=
client
.
NewGoShimmerAPI
(
"http://localhost:8080"
,
http
.
Client
{
Timeout
:
30
*
time
.
Second
})
node1APIURL
:=
"http://127.0.0.1:8080"
node2APIURL
:=
"http://127.0.0.1:8090"
// genesis wallet
genesisSeedBytes
,
err
:=
base58
.
Decode
(
"7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih"
)
if
err
!=
nil
{
if
node1APIURL
==
node2APIURL
{
fmt
.
Println
(
"Please use 2 different nodes to issue a double-spend"
)
return
}
clients
[
0
]
=
client
.
NewGoShimmerAPI
(
node1APIURL
,
http
.
Client
{
Timeout
:
60
*
time
.
Second
})
clients
[
1
]
=
client
.
NewGoShimmerAPI
(
node2APIURL
,
http
.
Client
{
Timeout
:
60
*
time
.
Second
})
myWallet
:=
wallet
.
New
()
myAddr
:=
myWallet
.
Seed
()
.
Address
(
0
)
if
_
,
err
:=
clients
[
0
]
.
SendFaucetRequest
(
myAddr
.
String
());
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
var
myOutputID
string
var
confirmed
bool
// wait for the funds
for
i
:=
0
;
i
<
10
;
i
++
{
time
.
Sleep
(
5
*
time
.
Second
)
resp
,
err
:=
clients
[
0
]
.
GetUnspentOutputs
([]
string
{
myAddr
.
String
()})
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
fmt
.
Println
(
"Waiting for funds to be confirmed..."
)
for
_
,
v
:=
range
resp
.
UnspentOutputs
{
if
len
(
v
.
OutputIDs
)
>
0
{
myOutputID
=
v
.
OutputIDs
[
0
]
.
ID
confirmed
=
v
.
OutputIDs
[
0
]
.
InclusionState
.
Confirmed
break
}
}
if
myOutputID
!=
""
&&
confirmed
{
break
}
}
const
genesisBalance
=
1000000000
genesisWallet
:=
wallet
.
New
(
genesisSeedBytes
)
genesisAddr
:=
genesisWallet
.
Seed
()
.
Address
(
0
)
genesisOutputID
:=
transaction
.
NewOutputID
(
genesisAddr
,
transaction
.
GenesisID
)
if
myOutputID
==
""
{
fmt
.
Println
(
"Could not find OutputID"
)
return
}
if
!
confirmed
{
fmt
.
Println
(
"OutputID not confirmed"
)
return
}
out
,
err
:=
transaction
.
OutputIDFromBase58
(
myOutputID
)
if
err
!=
nil
{
fmt
.
Println
(
"malformed OutputID"
)
return
}
// issue transactions which spend the same
genesis output in all partitions
// issue transactions which spend the same
output
conflictingTxs
:=
make
([]
*
transaction
.
Transaction
,
2
)
conflicting
Tx
IDs
:=
make
([]
string
,
2
)
conflicting
Msg
IDs
:=
make
([]
string
,
2
)
receiverSeeds
:=
make
([]
*
wallet
.
Seed
,
2
)
var
wg
sync
.
WaitGroup
for
i
:=
range
conflictingTxs
{
wg
.
Add
(
1
)
go
func
(
i
int
)
{
defer
wg
.
Done
()
// create a new receiver wallet for the given conflict
receiverSeeds
[
i
]
=
wallet
.
NewSeed
()
destAddr
:=
receiverSeeds
[
i
]
.
Address
(
0
)
fmt
.
Println
(
i
)
tx
:=
transaction
.
New
(
transaction
.
NewInputs
(
genesisOutputID
),
transaction
.
NewOutputs
(
map
[
address
.
Address
][]
*
balance
.
Balance
{
destAddr
:
{
{
Value
:
genesisBalance
,
Color
:
balance
.
ColorIOTA
},
},
}))
tx
=
tx
.
Sign
(
signaturescheme
.
ED25519
(
*
genesisWallet
.
Seed
()
.
KeyPair
(
0
)))
conflictingTxs
[
i
]
=
tx
// create a new receiver wallet for the given conflict
receiverSeeds
[
i
]
=
wallet
.
NewSeed
()
destAddr
:=
receiverSeeds
[
i
]
.
Address
(
0
)
valueObject
:=
valuepayload
.
New
(
valuepayload
.
GenesisID
,
valuepayload
.
GenesisID
,
tx
)
tx
:=
transaction
.
New
(
transaction
.
NewInputs
(
out
),
transaction
.
NewOutputs
(
map
[
address
.
Address
][]
*
balance
.
Balance
{
destAddr
:
{
{
Value
:
1337
,
Color
:
balance
.
ColorIOTA
},
},
}))
tx
=
tx
.
Sign
(
signaturescheme
.
ED25519
(
*
myWallet
.
Seed
()
.
KeyPair
(
0
)))
conflictingTxs
[
i
]
=
tx
// issue the value object
txID
,
err
:=
client
.
SendPayload
(
valueObject
.
Bytes
())
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
conflictingTxIDs
[
i
]
=
txID
fmt
.
Printf
(
"issued conflict transaction %s
\n
"
,
txID
)
//time.Sleep(7 * time.Second)
valueObject
:=
valuepayload
.
New
(
valuepayload
.
GenesisID
,
valuepayload
.
GenesisID
,
tx
)
// issue the tx
conflictingMsgIDs
[
i
],
err
=
clients
[
i
]
.
SendPayload
(
valueObject
.
Bytes
())
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
fmt
.
Printf
(
"issued conflict transaction %s
\n
"
,
conflictingMsgIDs
[
i
])
}(
i
)
}
wg
.
Wait
()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment