Class: GlWallet

Inherits:
Object
  • Object
show all
Defined in:
lib/gl_wallet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(network, is_mainnet, secret, url) ⇒ GlWallet

Returns a new instance of GlWallet.



7
8
9
10
11
12
# File 'lib/gl_wallet.rb', line 7

def initialize(network, is_mainnet, secret, url)
    self.network = network
    self.is_mainnet = is_mainnet
    self.secret = secret
    self.url = url
end

Instance Attribute Details

#is_mainnetObject

Returns the value of attribute is_mainnet.



5
6
7
# File 'lib/gl_wallet.rb', line 5

def is_mainnet
  @is_mainnet
end

#networkObject

Returns the value of attribute network.



5
6
7
# File 'lib/gl_wallet.rb', line 5

def network
  @network
end

#secretObject

Returns the value of attribute secret.



5
6
7
# File 'lib/gl_wallet.rb', line 5

def secret
  @secret
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/gl_wallet.rb', line 5

def url
  @url
end

Instance Method Details

#authenticateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gl_wallet.rb', line 14

def authenticate
    user_id = self.secret # Replace with the actual user ID

    # Create a Hash with the request body for token generation
    token_generation_payload = {
    'userId' => user_id
    }

    # Make the POST request for token generation
    token_url = URI("#{self.url}/api/v1/genarateTokens")
    token_generation_request = Net::HTTP::Post.new(token_url, {'Content-Type' => 'application/json'})
    token_generation_request.body = token_generation_payload.to_json

    token_generation_response = Net::HTTP.start(token_url.hostname, token_url.port) do |http|
    http.request(token_generation_request)
    end

    jwt_token = JSON.parse(token_generation_response.body)['data']['token']

    puts "JWT Token #{jwt_token}"
    jwt_token
end

#create_bulk_accounts(n = 50) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gl_wallet.rb', line 37

def create_bulk_accounts(n = 50)
    token = authenticate
     = URI("#{self.url}/api/v1/account/createBulk")
    # Headers for JSON content and authorization
    headers = {
    'Content-Type' => 'application/json',
    'Authorization' => "Bearer #{token}" # Replace YOUR_JWT_TOKEN with your actual JWT token
    }

    # Create a Hash with the request body for creating bulk accounts
    create_bulk_payload = {
    'network' => self.network,
    'isMainnet' => self.is_mainnet,
    'n' => n
    }

    # Make the POST request for creating bulk accounts
    create_bulk_request = Net::HTTP::Post.new(, headers)
    create_bulk_request.body = create_bulk_payload.to_json

    create_bulk_response = Net::HTTP.start(.hostname, .port) do |http|
    http.request(create_bulk_request)
    end
    
    puts "Create Bulk Account Response Code: #{create_bulk_response.code}"
    puts "Create Bulk Account Response Body: #{create_bulk_response.body}"

    JSON.parse(create_bulk_response.body).dig("data")
end